clean and optimize define handler