added some optimizations