got rid of the unterminated functions and the redeclaration of variables