Rewrite partially

Still needs some more rewrite