move function to top level

This is due to upvalue stuff under 5.1.
Thanks pygy.
handle removal

thanks Egil Hjelmeland