fixing and refactoring dart backend.