reorganized logic