Moved the graphic rendering code to it's own function.