Merged Misho's and Jassen's solutions.