cleanup and optimizing