Refactored boolean logic