clean up and optimization