Lots of refactoring.
Working version, start testing the clean script and add real triggers.