Utility function from codeswarm