Ribbon Home interview question

refactor this code in the best way possible.