Implementing matrix library