major refactoring.
not compatible with older version.