This could use a better interface, but it works for now.