Tidying things up and moving some functions to ubik.