Cleaning up code

Trying to make code a bit more organised and abstract