slightly change code style and fixed some small bugs