several optimizations added