added comments and fixes for minor bugs