cleaned up the code a bit, added more comments