Refactoring to be more modular and cleaned code.