reorganized code