Refactor data flow.

Related #123