merge from mikael jorhult newest code