rewrite of the whole damned thing

but it works!