count rows before inserting