Changing matrix retrieval function to use function for moving memory