Partial rewrite

Currently broken