improving code
added templates to matrix library