Refinement and cleanup

Refinement and cleanup