Refactor various code.