updated version according to Dr. So's suggestions