refactored MP code