A couple of logic/bug fixes for util functions.