Refactored some image rendering code

Also used higher level APIs