Lots of fixes
Code cleanup