total refactor fix of api