added if/else function logic