cleaned up, added more comments