Code reformat, removed unnecessary checks, tiny fixes

Sorry, may look like too many changes, but mainly formatting and some basic fixes/improvements.