adapted the code to the latest version