Clean and optimization code