optimizations done by Michael