cleaning up code a bit, trying to improve encapsulation