move logic from bin to lib