Fixed more bugs in script