Fix bugs and comment code