Many cleanup changes, some code fixes etc.