Improve rendering code

see 2363ffc