Extracting closures into methods to solve php 5.3 issue #546