Making things more modular and code cleanup