fixed bugs that avoided MPS, some code cleaning