Move KeyDef to separate class