adapting the code to the latest api version