made optimization compatible for older php versions