cleaned up a bit, added some comments