Refactor gui code.