perf improvements (thanks phpBB2refugees for motivating me)