modifing the new code to fit the new api