Reorganized code