Main function now waits for render threads before terminating.