refactored mp and functions