Reorganized code for future changes