Update MX selection

Added custom random MX/IP functions and did some tidying-up.