Compilied merge with mike's work.