Fixed bug by gathering flex at right time, but only once.
Fixed tests and refactored out dead code.