Separate the UVController function out and make it generic

Also fix a timing bug in it.