added some optimizations(?)