redo lost commit in reverted PR
fix tests and add tests for all that check max