bug fix and refinement.