Added conditional statement; see comments in code