more robust in-memory version