refactored towards cakepattern, making it easy for integration test to use inmemdb