Fixed bugs, added a test file