Lots of style changes

And improved code in some places, removed duplicate files, etc.