fixed limit-checking logic