Refactor render and window code