bug fixes and adding test script