Shortened insert code using function and testing