restructured code to fix text display errors