Corrected function logic for testing surjectiveness.