finished rewriting in dart