Improved structure for writing GUI functions

used variable better to parameterize