Some cleanup in ApiHandler