fixed templates and added a matrix class