db insertion logic