Rewrite to make scaleable