code cleanup and optimizations