fixing bugs in script