fixed bugs, added test script