fix bug in mock function, add tests