Fix crash and duplicated work