Tidy up utility code