Fixed matrix generation file.
Fixed adjusting algorithm at the end of two phases method.
Fixed minor bugs.