moved functions to start of code, added tests to verify the incoming data