Works better, but still not perfect. See TODO.