Implemented permute and contract functions, haven't yet checked all use cases