started working on overall rewrite