Support for matrices (#1) and some fixes