initial code from pb4php