restructured into class. still crashing on dartium but works when compiled to js