move main logic to lib