Fixed some calls to variables in functions

and added a comment of the error being thrown.