Various fixes by Ferhat