Fixed backwards detection logic