optimizing mocking logic