implements a number of refinements to refine
fixed a bug