Added some hacking from a session with @bagnell.