Lots of changes, re-org code