added optimizations to engine