Stop querying db when upper limit reached
Give missing cast