updated defensive code