move functions from bin file to lib for easier testability