The Mathematical Structure Of Non-Locality And Contextuality