Cleaned up normalization, docstrings, and comments; reverted to old 'ifmain' block