Fix call-time pass-by-reference and do some cleanup

Call-time pass-by-reference has been removed in PHP 5.4, so solve the
task differently.

Does some code cleanup along the way.