Move library functions to separate module, thread loading