some code optimizations, reduce consumption of flash rom