optimize if/else conditioning