Added several fixes by Trojanz