Refactor, code clean up, and lint fix.