refactoring and resorting.  much neater and better organised now.