rewrite the whole damn thing

Change-Id: I3267dc6b20b191f468ec44a6470410c29708aa2e