implemented some optimizations