Fix bug in limit code