Fixed scoping issues, class definitions, and other errors related to dynamically defining classes