Cleaned up function definition generation and moved it in its own file.
Implemented a cleaner version of the 'return a local' optimization.