Moved $limits to start of select statement