improved code in updateResCount