Cleaning up main logic