Refactored some logic to separate file;