tested and refined mpip script