Refactor to make functions more modular, and not to add layers