clean up code and optimize function initializeUi()