code cleanup + some seperation of concern