Refactored to include file types as a parameter of insert function.