commented code, fixed minor bugs