Cleaned up client code significantly, added some necessary comments