cleanup, more library functions and bugfixes for closures