fix bug in mock function, add tests
fix bug in mock