add non-global version and some bugfixes