Added Huiting's bug fixes