Refactor renderloop