moved main logic to lib directory