Fixed a bug in refinement implementation