[WIP] Big cleanup

Delete lots of unused code, fix some style, make things more consistent, general code quality.