Oil-in-water and water-in-oil emulsions formation and demulsification