Rewritten using code from dart2js