swap if tests to avoid possible segv