Refactored to separate rendering from window