snapshot middleware refactor