[MS] Refactor code.