Extracted LazyFactory (closes #24)

By introducing LazyFactory, I made its 'caching' function more testable.