Code adapted for PHP4