Added check to make sure leg exists in database