Added some refactored code

Trying to implement a cleaner design.