Added comments and cleaned code. Cleanded up tests.