updated average cost and templates also added model to save the data