Updated to compatibility with PHP5