Reworked for new API

I temporary set my fork for this task. You can change it after merge.