Code format and fixes

Bunch of fixes, code format changes etc.