added JP's old code