Safe insertion to db