refactor code to match new API