Add comments, fix minor bugs