Added support for tables and functions
Done some optimizations
Reorganized code