cleaned and improved text rendering code