Further fixes based on davec's and oga's suggestions