This should probably be refactored out into a static util class