Improvements taken from Marick's solutions