Move common code to 2 branches of an 'if' out of it

Still optimizing EUID...