Minor tweaks:

* Whitespace
* Formatting
* Consistent guard clauses
* Use array_map to avoid passing by reference