several code optimizations