Refactor #4240 & #4003: Refactor api to fit -x api