Fix tests, move inline functions out of loops.