bug fixes, completed script file, added tests