Optimize code structure to avoid else statement

Remove else statement for more clarity in the code