clean up save function and fix insert when user defined pkey