Added mlib.shape and fixed several bugs