Moves logic to lib