Added some comments and corrected var function declaration