Move function from bin/ to lib/ so it's accessible outside cli