fixed minor bugs, added more comments