@maxogden rewrote in 1/4 the code