added some more comments
cleaned up the code a bit more