Refactor

Took a shot at doing some refactoring to clean up the code