prepare the drawing environment and refactor a bit