cleaned up by adding a commonly used helper function.