Fixed bug in row insertion function