refactor.

- split file.
- replace routines.