Fix bug in max limit logic