Refactor encapsulate functionality, call from main