added support for functions
added simple scopes
added complex functions