Added missing check for NULL pointer returned from map function