Added logic to support in-memory and permanent database options

Found the bug and all tests now run successfully.