refactored initGraphicsContext