Fixed bug with building insert query statement