Some more fixes. Still needs testing