major code refinement