Code cleanup: minor style, formatting, semantics improvements and fixes

Not sure if I should've done this at the current stage, but I just couldn't resist to make the code a bit cleaner.