Guard max value

This is what I would write for #360 and #363.
Feel free to close it or merge it.