Added proper scoping for if/else blocks
merge