Added conditional logic and output