LPS-47370 remove duplicated logic (it was already duplicated in the jsp!) and reorder all the logic alphabetically so that it is clearer