Applied patches suggested by zanchey