restructured everything, almost a rewrite