Moving to abstraction and cleaning up code