fixed searchById() to avoid returning null objects