Improvements suggested by kibit.
Changes suggested by eastwood
Fixed failing constraint test