Small optimizations, code cleanup