Some more optimizations. While here do some cleanup