move rendering out of eventloop