Added proper check for maxitems