Moving functions to lib for loading