AdjustMatrix done. Beginning code refactoring