Rewritten for speed