Better way to write this function?

No description
Continue to help post