Neatened up code, added some encapsulation - stable