Several speed improvements at minor readability decrease.