Fix bug in fetch and add unit tests.