restructure

also generalise a few things