reviewd and fixed a few bugs