Move more inline php to a function