Refactor and prepared for testing