cleaned up, added some comments