add more comments; fix bugs