fixed bug and some redundant processing.