Refactoring

@dbudell 
Did a lot here, let me know if you have questions.