Fixed bugs in server script from code refactor