Fix bug. NullPointerException for null max or min length
Little code refactoring