modify refine layer algorithm done