implemented function templates (including descriptive comments) for programming assignment 2