First batch of fixes thanks to igor
igor fixes