bug fix & make it php 5.2 friendly