Separated the tests in to test functions depending on what they are testing. Moved some test-specific functiosn in to closures within the test functions themselves.