Reorganized some code. No functional change intended