Refactor to try turn more comprehensive with better practices.

No functionality was changed.