merging changes from anders-synstad fork