Fixed a bug in MS mode and added a test.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>