Move utility function to Utils class, and minor cleanup