Rewrite

Currently broken due to incomplete changes