Made code a bit more object-oriented