Relocated select code, fixed wierd bug with limiting row count