Rewrote validator from scratch

This is very hard work but should be usable now!