Some major formatting, code-style and other fixes