rewrote to find logic problem