refactor renderloop