I'm wondering is there a better approach to the currently implemented version of this function. Suggestions are welcome below on how it can/could be improved.