cleaned up bulk insert and fixed a bug