CID-1114601/CID-1114602 Fix ignored return values and remove duplicate code