Add data mapper pattern and fix bugs.