Simplified if blocks for clarity as per vmehra review.