Refactoring

- Use a single run-time function to look up variables, to reduce the amount of generated code.
- Added header comments to some functions at the start of the file, since there is a lack of documentation in this module.