Added some more comments and fixed some minor bugs