Some cleanups etc.
Various fixes and improvements.