added tests, and the main code