Re-organizing code structure. A bit cleaner. Still needs work.