Rearranged gui code