code merge and clean up