Quite a few changes

Reorganized code