Refactored the final boolean expression