A bunch of comments, code cleanup and small reliability tweaks