matrix class prototype refactor