Move generic helper functions to Util.hs.