Refactored main src file to simplify testing