Improving the method based on feedback and make it compatible with PHP <= 5.3