Code restyling and add some comments
Various improvements