Merge "Decimal number is treated as outputText"
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index a9474a0..b513d96 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -111,10 +111,6 @@
         <attr name="keyPreviewOffset" format="dimension" />
         <!-- Height of the key press feedback popup. -->
         <attr name="keyPreviewHeight" format="dimension" />
-        <!-- Duration of key preview popup zoom in animation in millisecond -->
-        <attr name="keyPreviewZoomInDuration" format="integer" />
-        <!-- Duration of key preview popup zoom out animation in millisecond -->
-        <attr name="keyPreviewZoomOutDuration" format="integer" />
         <!-- Delay after key releasing and key press feedback dismissing in millisecond -->
         <attr name="keyPreviewLingerTimeout" format="integer" />
         <!-- Layout resource for more keys keyboard -->
@@ -240,6 +236,7 @@
     </declare-styleable>
 
     <declare-styleable name="Keyboard_Key">
+        <!-- TODO: Remove code attribute and consolidate with keySpec. -->
         <!-- The unicode value that this key outputs.
              Code value represented in hexadecimal prefixed with "0x" or code value reference using
              "!code/<code_name>" notation. -->
@@ -275,8 +272,7 @@
             <flag name="altCodeWhileTyping" value="0x04" />
             <flag name="enableLongPress" value="0x08" />
         </attr>
-        <!-- The string of characters to output when this key is pressed. -->
-        <attr name="keyOutputText" format="string" />
+        <!-- TODO: Rename keyLabel to keySpec. -->
         <!-- The label to display on the key. -->
         <attr name="keyLabel" format="string" />
         <!-- The hint label to display on the key in conjunction with the label. -->
@@ -318,6 +314,7 @@
             <!-- If true, disable additionalMoreKeys. -->
             <flag name="disableAdditionalMoreKeys" value="0x80000000" />
         </attr>
+        <!-- TODO: Remove keyIcon attribute and consolidate with keySpec. -->
         <!-- The icon to display on the key instead of the label. -->
         <attr name="keyIcon" format="string" />
         <!-- The icon for disabled key -->
diff --git a/java/res/values/config-common.xml b/java/res/values/config-common.xml
index c920152..1b44bad 100644
--- a/java/res/values/config-common.xml
+++ b/java/res/values/config-common.xml
@@ -35,8 +35,10 @@
 
     <integer name="config_ignore_alt_code_key_timeout">350</integer>
 
-    <integer name="config_key_preview_zoom_in_duration">35</integer>
-    <integer name="config_key_preview_zoom_out_duration">40</integer>
+    <integer name="config_key_preview_show_up_duration">35</integer>
+    <integer name="config_key_preview_dismiss_duration">40</integer>
+    <fraction name="config_key_preview_show_up_start_scale">70%</fraction>
+    <fraction name="config_key_preview_dismiss_end_scale">70%</fraction>
     <integer name="config_key_preview_linger_timeout">70</integer>
     <!-- Suppress showing key preview duration after batch input in millisecond -->
     <integer name="config_suppress_key_preview_after_batch_input_duration">1000</integer>
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index 70f4c18..b762af3 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -486,6 +486,14 @@
     <string name="prefs_keypress_vibration_duration_settings">Keypress vibration duration</string>
     <!-- Title of the settings for keypress sound volume [CHAR LIMIT=35] -->
     <string name="prefs_keypress_sound_volume_settings">Keypress sound volume</string>
+    <!-- Title of the settings for key popup show up animation duration (in milliseconds) [CHAR LIMIT=35] -->
+    <string name="prefs_key_popup_show_up_duration_settings" translatable="false">Key popup show up duration</string>
+    <!-- Title of the settings for key popup dismiss animation duration (in milliseconds) [CHAR LIMIT=35] -->
+    <string name="prefs_key_popup_dismiss_duration_settings" translatable="false">Key popup dismiss duration</string>
+    <!-- Title of the settings for key popup show up animation start scale (in percentile) [CHAR LIMIT=35] -->
+    <string name="prefs_key_popup_show_up_start_scale_settings" translatable="false">Key popup show up start scale</string>
+    <!-- Title of the settings for key popup dismiss animation end scale (in percentile) [CHAR LIMIT=35] -->
+    <string name="prefs_key_popup_dismiss_end_scale_settings" translatable="false">Key popup dismiss end scale</string>
     <!-- Title of the settings for reading an external dictionary file -->
     <string name="prefs_read_external_dictionary">Read external dictionary file</string>
     <!-- Title of the settings for using only personalization dictionary -->
diff --git a/java/res/values/themes-common.xml b/java/res/values/themes-common.xml
index 3bfd73a..fc96d19 100644
--- a/java/res/values/themes-common.xml
+++ b/java/res/values/themes-common.xml
@@ -77,8 +77,6 @@
         <item name="ignoreAltCodeKeyTimeout">@integer/config_ignore_alt_code_key_timeout</item>
         <item name="keyPreviewLayout">@layout/key_preview</item>
         <item name="keyPreviewHeight">@dimen/config_key_preview_height</item>
-        <item name="keyPreviewZoomInDuration">@integer/config_key_preview_zoom_in_duration</item>
-        <item name="keyPreviewZoomOutDuration">@integer/config_key_preview_zoom_out_duration</item>
         <item name="keyPreviewLingerTimeout">@integer/config_key_preview_linger_timeout</item>
         <item name="moreKeysKeyboardLayout">@layout/more_keys_keyboard</item>
         <item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>
diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml
index d817add..4e4579b 100644
--- a/java/res/xml-sw600dp/key_styles_common.xml
+++ b/java/res/xml-sw600dp/key_styles_common.xml
@@ -101,12 +101,6 @@
         latin:keyLabelFlags="hasPopupHint"
         latin:keyActionFlags="noKeyPreview" />
     <key-style
-        latin:styleName="smileyKeyStyle"
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyLabelFlags="hasPopupHint|preserveCase"
-        latin:moreKeys="!text/more_keys_for_smiley" />
-    <key-style
         latin:styleName="shortcutKeyStyle"
         latin:code="!code/key_shortcut"
         latin:keyIcon="!icon/shortcut_key"
@@ -190,8 +184,7 @@
         latin:parentStyle="baseForLayoutSwitchKeyStyle" />
     <key-style
         latin:styleName="comKeyStyle"
-        latin:keyLabel="!text/keylabel_for_popular_domain"
+        latin:keyLabel="!text/keylabel_for_popular_domain|!text/keylabel_for_popular_domain"
         latin:keyLabelFlags="autoXScale|fontNormal|hasPopupHint|preserveCase"
-        latin:keyOutputText="!text/keylabel_for_popular_domain"
         latin:moreKeys="!text/more_keys_for_popular_domain" />
 </merge>
diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml
index d538eb8..9c40d62 100644
--- a/java/res/xml/key_styles_common.xml
+++ b/java/res/xml/key_styles_common.xml
@@ -184,9 +184,8 @@
         latin:parentStyle="baseForToSymbolKeyStyle" />
     <key-style
         latin:styleName="comKeyStyle"
-        latin:keyLabel="!text/keylabel_for_popular_domain"
+        latin:keyLabel="!text/keylabel_for_popular_domain|!text/keylabel_for_popular_domain"
         latin:keyLabelFlags="autoXScale|fontNormal|hasPopupHint|preserveCase"
-        latin:keyOutputText="!text/keylabel_for_popular_domain"
         latin:moreKeys="!text/more_keys_for_popular_domain"
         latin:backgroundType="functional" />
 </merge>
diff --git a/java/res/xml/prefs_for_debug.xml b/java/res/xml/prefs_for_debug.xml
index 899e2b8..81a5d98 100644
--- a/java/res/xml/prefs_for_debug.xml
+++ b/java/res/xml/prefs_for_debug.xml
@@ -14,68 +14,75 @@
      limitations under the License.
 -->
 
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
-        android:title="@string/prefs_debug_mode"
-        android:key="english_ime_debug_settings">
-
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+    android:title="@string/prefs_debug_mode"
+    android:key="english_ime_debug_settings"
+>
     <CheckBoxPreference
-            android:key="enable_logging"
-            android:title="@string/prefs_enable_log"
-            android:summary="@string/prefs_description_log"
-            android:persistent="true"
-            android:defaultValue="false" />
-
+        android:key="enable_logging"
+        android:title="@string/prefs_enable_log"
+        android:summary="@string/prefs_description_log"
+        android:persistent="true"
+        android:defaultValue="false" />
     <ListPreference
-            android:key="pref_keyboard_layout_20110916"
-            android:title="@string/keyboard_layout"
-            android:summary="%s"
-            android:persistent="true"
-            android:entryValues="@array/keyboard_layout_modes_values"
-            android:entries="@array/keyboard_layout_modes"
-            android:defaultValue="@string/config_default_keyboard_theme_index" />
-
+        android:key="pref_keyboard_layout_20110916"
+        android:title="@string/keyboard_layout"
+        android:summary="%s"
+        android:persistent="true"
+        android:entryValues="@array/keyboard_layout_modes_values"
+        android:entries="@array/keyboard_layout_modes"
+        android:defaultValue="@string/config_default_keyboard_theme_index" />
     <CheckBoxPreference
-            android:key="debug_mode"
-            android:title="@string/prefs_debug_mode"
-            android:persistent="true"
-            android:defaultValue="false" />
-
+        android:key="debug_mode"
+        android:title="@string/prefs_debug_mode"
+        android:persistent="true"
+        android:defaultValue="false" />
     <CheckBoxPreference
-            android:key="force_non_distinct_multitouch"
-            android:title="@string/prefs_force_non_distinct_multitouch"
-            android:persistent="true"
-            android:defaultValue="false" />
-
+        android:key="force_non_distinct_multitouch"
+        android:title="@string/prefs_force_non_distinct_multitouch"
+        android:persistent="true"
+        android:defaultValue="false" />
     <CheckBoxPreference
-            android:key="usability_study_mode"
-            android:title="@string/prefs_usability_study_mode"
-            android:persistent="true"
-            android:defaultValue="false" />
-
+        android:key="usability_study_mode"
+        android:title="@string/prefs_usability_study_mode"
+        android:persistent="true"
+        android:defaultValue="false" />
+    <com.android.inputmethod.latin.settings.SeekBarDialogPreference
+        android:key="pref_key_preview_show_up_start_scale"
+        android:title="@string/prefs_key_popup_show_up_start_scale_settings"
+        latin:maxValue="100" /> <!-- percent -->
+    <com.android.inputmethod.latin.settings.SeekBarDialogPreference
+        android:key="pref_key_preview_dismiss_end_scale"
+        android:title="@string/prefs_key_popup_dismiss_end_scale_settings"
+        latin:maxValue="100" /> <!-- percent -->
+    <com.android.inputmethod.latin.settings.SeekBarDialogPreference
+        android:key="pref_key_preview_show_up_duration"
+        android:title="@string/prefs_key_popup_show_up_duration_settings"
+        latin:maxValue="100" /> <!-- milliseconds -->
+    <com.android.inputmethod.latin.settings.SeekBarDialogPreference
+        android:key="pref_key_preview_dismiss_duration"
+        android:title="@string/prefs_key_popup_dismiss_duration_settings"
+        latin:maxValue="100" /> <!-- milliseconds -->
     <CheckBoxPreference
         android:defaultValue="false"
         android:key="use_only_personalization_dictionary_for_debug"
         android:persistent="true"
         android:title="@string/prefs_use_only_personalization_dictionary" />
-
     <PreferenceScreen
         android:key="read_external_dictionary"
         android:title="@string/prefs_read_external_dictionary" />
-
     <PreferenceScreen
         android:key="dump_contacts_dict"
         android:title="@string/prefs_dump_contacts_dict" />
-
     <PreferenceScreen
         android:key="dump_user_dict"
         android:title="@string/prefs_dump_user_dict" />
-
     <PreferenceScreen
         android:key="dump_user_history_dict"
         android:title="@string/prefs_dump_user_history_dict" />
-
     <PreferenceScreen
         android:key="dump_personalization_dict"
         android:title="@string/prefs_dump_personalization_dict" />
-
 </PreferenceScreen>
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index f7eec6b..1b9007d 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -267,12 +267,6 @@
                 R.styleable.Keyboard_Key_visualInsetsLeft, baseWidth, baseWidth, 0));
         final int visualInsetsRight = Math.round(keyAttr.getFraction(
                 R.styleable.Keyboard_Key_visualInsetsRight, baseWidth, baseWidth, 0));
-        mIconId = KeySpecParser.getIconId(style.getString(keyAttr,
-                R.styleable.Keyboard_Key_keyIcon));
-        final int disabledIconId = KeySpecParser.getIconId(style.getString(keyAttr,
-                R.styleable.Keyboard_Key_keyIconDisabled));
-        final int previewIconId = KeySpecParser.getIconId(style.getString(keyAttr,
-                R.styleable.Keyboard_Key_keyIconPreview));
 
         mLabelFlags = style.getFlags(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags)
                 | row.getDefaultKeyLabelFlags();
@@ -321,8 +315,21 @@
         }
         mActionFlags = actionFlags;
 
-        final int code = KeySpecParser.parseCode(style.getString(keyAttr,
+        final String keySpec = style.getString(keyAttr, R.styleable.Keyboard_Key_keyLabel);
+
+        final int iconIdInAttr = KeySpecParser.getIconId(style.getString(keyAttr,
+                R.styleable.Keyboard_Key_keyIcon));
+        mIconId = (iconIdInAttr != ICON_UNDEFINED) ? iconIdInAttr
+                : KeySpecParser.getIconId(keySpec);
+        final int disabledIconId = KeySpecParser.getIconId(style.getString(keyAttr,
+                R.styleable.Keyboard_Key_keyIconDisabled));
+        final int previewIconId = KeySpecParser.getIconId(style.getString(keyAttr,
+                R.styleable.Keyboard_Key_keyIconPreview));
+
+        final int codeInAttr = KeySpecParser.parseCode(style.getString(keyAttr,
                 R.styleable.Keyboard_Key_code), params.mCodesSet, CODE_UNSPECIFIED);
+        final int code = (codeInAttr != CODE_UNSPECIFIED) ? codeInAttr
+                : KeySpecParser.getCode(keySpec, params.mCodesSet);
         if ((mLabelFlags & LABEL_FLAGS_FROM_CUSTOM_ACTION_LABEL) != 0) {
             mLabel = params.mId.mCustomActionLabel;
         } else if (code >= Character.MIN_SUPPLEMENTARY_CODE_POINT) {
@@ -331,8 +338,8 @@
             // code point nor as a surrogate pair.
             mLabel = new StringBuilder().appendCodePoint(code).toString();
         } else {
-            mLabel = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
-                    R.styleable.Keyboard_Key_keyLabel), needsToUpperCase, locale);
+            mLabel = StringUtils.toUpperCaseOfStringForLocale(
+                    KeySpecParser.getLabel(keySpec), needsToUpperCase, locale);
         }
         if ((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) {
             mHintLabel = null;
@@ -340,8 +347,8 @@
             mHintLabel = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
                     R.styleable.Keyboard_Key_keyHintLabel), needsToUpperCase, locale);
         }
-        String outputText = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
-                R.styleable.Keyboard_Key_keyOutputText), needsToUpperCase, locale);
+        String outputText = StringUtils.toUpperCaseOfStringForLocale(
+                KeySpecParser.getOutputText(keySpec), needsToUpperCase, locale);
         // Choose the first letter of the label as primary code if not specified.
         if (code == CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
                 && !TextUtils.isEmpty(mLabel)) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 53b4485..9f98d29 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -37,6 +37,7 @@
 import com.android.inputmethod.latin.RichInputMethodManager;
 import com.android.inputmethod.latin.SubtypeSwitcher;
 import com.android.inputmethod.latin.WordComposer;
+import com.android.inputmethod.latin.settings.DebugSettings;
 import com.android.inputmethod.latin.settings.Settings;
 import com.android.inputmethod.latin.settings.SettingsValues;
 import com.android.inputmethod.latin.utils.ResourceUtils;
@@ -80,6 +81,7 @@
     private KeyboardState mState;
 
     private KeyboardLayoutSet mKeyboardLayoutSet;
+    private SettingsValues mCurrentSettingsValues;
 
     /** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of
      * what user actually typed. */
@@ -158,6 +160,7 @@
                 settingsValues.mShowsVoiceInputKey,
                 settingsValues.isLanguageSwitchKeyEnabled());
         mKeyboardLayoutSet = builder.build();
+        mCurrentSettingsValues = settingsValues;
         try {
             mState.onLoadKeyboard();
         } catch (KeyboardLayoutSetException e) {
@@ -189,8 +192,13 @@
         keyboardView.setKeyboard(keyboard);
         mCurrentInputView.setKeyboardTopPadding(keyboard.mTopPadding);
         keyboardView.setKeyPreviewPopupEnabled(
-                Settings.readKeyPreviewPopupEnabled(mPrefs, mResources),
-                Settings.readKeyPreviewPopupDismissDelay(mPrefs, mResources));
+                mCurrentSettingsValues.mKeyPreviewPopupOn,
+                mCurrentSettingsValues.mKeyPreviewPopupDismissDelay);
+        keyboardView.setKeyPreviewAnimationParams(
+                mCurrentSettingsValues.mKeyPreviewShowUpStartScale,
+                mCurrentSettingsValues.mKeyPreviewShowUpDuration,
+                mCurrentSettingsValues.mKeyPreviewDismissEndScale,
+                mCurrentSettingsValues.mKeyPreviewDismissDuration);
         keyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive);
         keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
         final boolean subtypeChanged = (oldKeyboard == null)
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index f3cfae2..ce41a31 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -421,6 +421,12 @@
         mKeyPreviewDrawParams.setPopupEnabled(previewEnabled, delay);
     }
 
+    public void setKeyPreviewAnimationParams(final float showUpStartScale, final int showUpDuration,
+            final float dismissEndScale, final int dismissDuration) {
+        mKeyPreviewDrawParams.setAnimationParams(
+                showUpStartScale, showUpDuration, dismissEndScale, dismissDuration);
+    }
+
     private void locatePreviewPlacerView() {
         if (mDrawingPreviewPlacerView.getParent() != null) {
             return;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java
index df869b2..ff197ba 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java
@@ -100,7 +100,7 @@
         if (withAnimation) {
             if (tag instanceof KeyPreviewAnimations) {
                 final KeyPreviewAnimations animation = (KeyPreviewAnimations)tag;
-                animation.startZoomOut();
+                animation.startDismiss();
             }
             return;
         }
@@ -198,87 +198,87 @@
         }
 
         // Show preview with animation.
-        final Animator zoomIn = createZoomInAniation(key, previewTextView);
-        final Animator zoomOut = createZoomOutAnimation(key, previewTextView);
-        final KeyPreviewAnimations animation = new KeyPreviewAnimations(zoomIn, zoomOut);
+        final Animator showUpAnimation = createShowUpAniation(key, previewTextView);
+        final Animator dismissAnimation = createDismissAnimation(key, previewTextView);
+        final KeyPreviewAnimations animation = new KeyPreviewAnimations(
+                showUpAnimation, dismissAnimation);
         previewTextView.setTag(animation);
-        animation.startZoomIn();
+        animation.startShowUp();
     }
 
-    // TODO: Move these parameters to resources or preferences.
-    private static final float KEY_PREVIEW_START_ZOOM_IN_SCALE = 0.7f;
-    private static final float KEY_PREVIEW_END_ZOOM_IN_SCALE = 1.0f;
-    private static final float KEY_PREVIEW_END_ZOOM_OUT_SCALE = 0.7f;
+    private static final float KEY_PREVIEW_SHOW_UP_END_SCALE = 1.0f;
     private static final AccelerateInterpolator ACCELERATE_INTERPOLATOR =
             new AccelerateInterpolator();
     private static final DecelerateInterpolator DECELERATE_INTERPOLATOR =
             new DecelerateInterpolator();
 
-    private Animator createZoomInAniation(final Key key, final TextView previewTextView) {
+    private Animator createShowUpAniation(final Key key, final TextView previewTextView) {
+        // TODO: Optimization for no scale animation and no duration.
         final ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(
-                previewTextView, View.SCALE_X, KEY_PREVIEW_START_ZOOM_IN_SCALE,
-                KEY_PREVIEW_END_ZOOM_IN_SCALE);
+                previewTextView, View.SCALE_X, mParams.getShowUpStartScale(),
+                KEY_PREVIEW_SHOW_UP_END_SCALE);
         final ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(
-                previewTextView, View.SCALE_Y, KEY_PREVIEW_START_ZOOM_IN_SCALE,
-                KEY_PREVIEW_END_ZOOM_IN_SCALE);
-        final AnimatorSet zoomInAnimation = new AnimatorSet();
-        zoomInAnimation.play(scaleXAnimation).with(scaleYAnimation);
-        // TODO: Implement preference option to control key preview animation duration.
-        zoomInAnimation.setDuration(mParams.mZoomInDuration);
-        zoomInAnimation.setInterpolator(DECELERATE_INTERPOLATOR);
-        zoomInAnimation.addListener(new AnimatorListenerAdapter() {
+                previewTextView, View.SCALE_Y, mParams.getShowUpStartScale(),
+                KEY_PREVIEW_SHOW_UP_END_SCALE);
+        final AnimatorSet showUpAnimation = new AnimatorSet();
+        showUpAnimation.play(scaleXAnimation).with(scaleYAnimation);
+        showUpAnimation.setDuration(mParams.getShowUpDuration());
+        showUpAnimation.setInterpolator(DECELERATE_INTERPOLATOR);
+        showUpAnimation.addListener(new AnimatorListenerAdapter() {
             @Override
             public void onAnimationStart(final Animator animation) {
                 showKeyPreview(key, previewTextView, false /* withAnimation */);
             }
         });
-        return zoomInAnimation;
+        return showUpAnimation;
     }
 
-    private Animator createZoomOutAnimation(final Key key, final TextView previewTextView) {
+    private Animator createDismissAnimation(final Key key, final TextView previewTextView) {
+        // TODO: Optimization for no scale animation and no duration.
         final ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(
-                previewTextView, View.SCALE_X, KEY_PREVIEW_END_ZOOM_OUT_SCALE);
+                previewTextView, View.SCALE_X, mParams.getDismissEndScale());
         final ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(
-                previewTextView, View.SCALE_Y, KEY_PREVIEW_END_ZOOM_OUT_SCALE);
-        final AnimatorSet zoomOutAnimation = new AnimatorSet();
-        zoomOutAnimation.play(scaleXAnimation).with(scaleYAnimation);
-        // TODO: Implement preference option to control key preview animation duration.
-        final int zoomOutDuration = Math.min(mParams.mZoomOutDuration, mParams.getLingerTimeout());
-        zoomOutAnimation.setDuration(zoomOutDuration);
-        zoomOutAnimation.setInterpolator(ACCELERATE_INTERPOLATOR);
-        zoomOutAnimation.addListener(new AnimatorListenerAdapter() {
+                previewTextView, View.SCALE_Y, mParams.getDismissEndScale());
+        final AnimatorSet dismissAnimation = new AnimatorSet();
+        dismissAnimation.play(scaleXAnimation).with(scaleYAnimation);
+        final int dismissDuration = Math.min(
+                mParams.getDismissDuration(), mParams.getLingerTimeout());
+        dismissAnimation.setDuration(dismissDuration);
+        dismissAnimation.setInterpolator(ACCELERATE_INTERPOLATOR);
+        dismissAnimation.addListener(new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(final Animator animation) {
                 dismissKeyPreview(key, false /* withAnimation */);
             }
         });
-        return zoomOutAnimation;
+        return dismissAnimation;
     }
 
     private static class KeyPreviewAnimations extends AnimatorListenerAdapter {
-        private final Animator mZoomIn;
-        private final Animator mZoomOut;
+        private final Animator mShowUpAnimation;
+        private final Animator mDismissAnimation;
 
-        public KeyPreviewAnimations(final Animator zoomIn, final Animator zoomOut) {
-            mZoomIn = zoomIn;
-            mZoomOut = zoomOut;
+        public KeyPreviewAnimations(final Animator showUpAnimation,
+                final Animator dismissAnimation) {
+            mShowUpAnimation = showUpAnimation;
+            mDismissAnimation = dismissAnimation;
         }
 
-        public void startZoomIn() {
-            mZoomIn.start();
+        public void startShowUp() {
+            mShowUpAnimation.start();
         }
 
-        public void startZoomOut() {
-            if (mZoomIn.isRunning()) {
-                mZoomIn.addListener(this);
+        public void startDismiss() {
+            if (mShowUpAnimation.isRunning()) {
+                mShowUpAnimation.addListener(this);
                 return;
             }
-            mZoomOut.start();
+            mDismissAnimation.start();
         }
 
         @Override
         public void onAnimationEnd(final Animator animation) {
-            mZoomOut.start();
+            mDismissAnimation.start();
         }
     }
 }
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java
index ff493b1..37e5c88 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java
@@ -26,9 +26,10 @@
     public final int mLayoutId;
     public final int mPreviewOffset;
     public final int mPreviewHeight;
-    // TODO: Move those parameters to preferences.
-    public final int mZoomInDuration;
-    public final int mZoomOutDuration;
+    private int mShowUpDuration;
+    private int mDismissDuration;
+    private float mShowUpStartScale;
+    private float mDismissEndScale;
     private int mLingerTimeout;
     private boolean mShowPopup = true;
 
@@ -69,10 +70,6 @@
         if (mLayoutId == 0) {
             mShowPopup = false;
         }
-        mZoomInDuration = mainKeyboardViewAttr.getInt(
-                R.styleable.MainKeyboardView_keyPreviewZoomInDuration, 0);
-        mZoomOutDuration = mainKeyboardViewAttr.getInt(
-                R.styleable.MainKeyboardView_keyPreviewZoomOutDuration, 0);
     }
 
     public void setVisibleOffset(final int previewVisibleOffset) {
@@ -117,4 +114,28 @@
     public int getLingerTimeout() {
         return mLingerTimeout;
     }
+
+    public void setAnimationParams(final float showUpStartScale, final int showUpDuration,
+            final float dismissEndScale, final int dismissDuration) {
+        mShowUpStartScale = showUpStartScale;
+        mShowUpDuration = showUpDuration;
+        mDismissEndScale = dismissEndScale;
+        mDismissDuration = dismissDuration;
+    }
+
+    public float getShowUpStartScale() {
+        return mShowUpStartScale;
+    }
+
+    public int getShowUpDuration() {
+        return mShowUpDuration;
+    }
+
+    public float getDismissEndScale() {
+        return mDismissEndScale;
+    }
+
+    public int getDismissDuration() {
+        return mDismissDuration;
+    }
 }
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStylesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStylesSet.java
index f7e43a6..a64f235 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyStylesSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStylesSet.java
@@ -138,7 +138,6 @@
             readString(keyAttr, R.styleable.Keyboard_Key_code);
             readString(keyAttr, R.styleable.Keyboard_Key_altCode);
             readString(keyAttr, R.styleable.Keyboard_Key_keyLabel);
-            readString(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
             readString(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
             readStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
             readStringArray(keyAttr, R.styleable.Keyboard_Key_additionalMoreKeys);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index b31358f..47e9142 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -276,9 +276,9 @@
 
             params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0);
             params.mIconsSet.loadIcons(keyboardAttr);
-            final String language = params.mId.mLocale.getLanguage();
-            params.mCodesSet.setLanguage(language);
-            params.mTextsSet.setLanguage(language);
+            final Locale locale = params.mId.mLocale;
+            params.mCodesSet.setLocale(locale);
+            params.mTextsSet.setLocale(locale);
             final RunInLocale<Void> job = new RunInLocale<Void>() {
                 @Override
                 protected Void job(final Resources res) {
@@ -287,9 +287,8 @@
                 }
             };
             // Null means the current system locale.
-            final Locale locale = SubtypeLocaleUtils.isNoLanguage(params.mId.mSubtype)
-                    ? null : params.mId.mLocale;
-            job.runInLocale(mResources, locale);
+            job.runInLocale(mResources,
+                    SubtypeLocaleUtils.isNoLanguage(params.mId.mSubtype) ? null : locale);
 
             final int resourceId = keyboardAttr.getResourceId(
                     R.styleable.Keyboard_touchPositionCorrectionData, 0);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
index aeb4db5..9f873ed 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
@@ -18,20 +18,20 @@
 
 import com.android.inputmethod.latin.Constants;
 import com.android.inputmethod.latin.utils.CollectionUtils;
+import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
 
 import java.util.HashMap;
+import java.util.Locale;
 
 public final class KeyboardCodesSet {
     public static final String PREFIX_CODE = "!code/";
 
-    private static final HashMap<String, int[]> sLanguageToCodesMap = CollectionUtils.newHashMap();
     private static final HashMap<String, Integer> sNameToIdMap = CollectionUtils.newHashMap();
 
     private int[] mCodes = DEFAULT;
 
-    public void setLanguage(final String language) {
-        final int[] codes = sLanguageToCodesMap.get(language);
-        mCodes = (codes != null) ? codes : DEFAULT;
+    public void setLocale(final Locale locale) {
+        mCodes = SubtypeLocaleUtils.isRtlLanguage(locale) ? RTL : DEFAULT;
     }
 
     public int getCode(final String name) {
@@ -134,18 +134,6 @@
         CODE_LEFT_CURLY_BRACKET,
     };
 
-    private static final String LANGUAGE_DEFAULT = "DEFAULT";
-    private static final String LANGUAGE_ARABIC = "ar";
-    private static final String LANGUAGE_PERSIAN = "fa";
-    private static final String LANGUAGE_HEBREW = "iw";
-
-    private static final Object[] LANGUAGE_AND_CODES = {
-        LANGUAGE_DEFAULT, DEFAULT,
-        LANGUAGE_ARABIC, RTL,
-        LANGUAGE_PERSIAN, RTL,
-        LANGUAGE_HEBREW, RTL,
-    };
-
     static {
         if (DEFAULT.length != RTL.length || DEFAULT.length != ID_TO_NAME.length) {
             throw new RuntimeException("Internal inconsistency");
@@ -153,11 +141,5 @@
         for (int i = 0; i < ID_TO_NAME.length; i++) {
             sNameToIdMap.put(ID_TO_NAME[i], i);
         }
-
-        for (int i = 0; i < LANGUAGE_AND_CODES.length; i += 2) {
-            final String language = (String)LANGUAGE_AND_CODES[i];
-            final int[] codes = (int[])LANGUAGE_AND_CODES[i + 1];
-            sLanguageToCodesMap.put(language, codes);
-        }
     }
 }
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
index f8c0988..4322345 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
@@ -25,6 +25,7 @@
 import com.android.inputmethod.latin.utils.CollectionUtils;
 
 import java.util.HashMap;
+import java.util.Locale;
 
 /**
  * !!!!! DO NOT EDIT THIS FILE !!!!!
@@ -52,15 +53,17 @@
     private static final int MAX_STRING_REFERENCE_INDIRECTION = 10;
 
     // Language to texts map.
-    private static final HashMap<String, String[]> sLocaleToTextsMap = CollectionUtils.newHashMap();
+    private static final HashMap<String, String[]> sLanguageToTextsMap =
+            CollectionUtils.newHashMap();
     private static final HashMap<String, Integer> sNameToIdsMap = CollectionUtils.newHashMap();
 
     private String[] mTexts;
     // Resource name to text map.
     private HashMap<String, String> mResourceNameToTextsMap = CollectionUtils.newHashMap();
 
-    public void setLanguage(final String language) {
-        mTexts = sLocaleToTextsMap.get(language);
+    public void setLocale(final Locale locale) {
+        final String language = locale.getLanguage();
+        mTexts = sLanguageToTextsMap.get(language);
         if (mTexts == null) {
             mTexts = LANGUAGE_DEFAULT;
         }
@@ -309,23 +312,22 @@
         /* 137 */ "label_time_pm",
         /* 138 */ "keylabel_for_popular_domain",
         /* 139 */ "more_keys_for_popular_domain",
-        /* 140 */ "more_keys_for_smiley",
-        /* 141 */ "single_laqm_raqm",
-        /* 142 */ "single_laqm_raqm_rtl",
-        /* 143 */ "single_raqm_laqm",
-        /* 144 */ "double_laqm_raqm",
-        /* 145 */ "double_laqm_raqm_rtl",
-        /* 146 */ "double_raqm_laqm",
-        /* 147 */ "single_lqm_rqm",
-        /* 148 */ "single_9qm_lqm",
-        /* 149 */ "single_9qm_rqm",
-        /* 150 */ "double_lqm_rqm",
-        /* 151 */ "double_9qm_lqm",
-        /* 152 */ "double_9qm_rqm",
-        /* 153 */ "more_keys_for_single_quote",
-        /* 154 */ "more_keys_for_double_quote",
-        /* 155 */ "more_keys_for_tablet_double_quote",
-        /* 156 */ "emoji_key_as_more_key",
+        /* 140 */ "single_laqm_raqm",
+        /* 141 */ "single_laqm_raqm_rtl",
+        /* 142 */ "single_raqm_laqm",
+        /* 143 */ "double_laqm_raqm",
+        /* 144 */ "double_laqm_raqm_rtl",
+        /* 145 */ "double_raqm_laqm",
+        /* 146 */ "single_lqm_rqm",
+        /* 147 */ "single_9qm_lqm",
+        /* 148 */ "single_9qm_rqm",
+        /* 149 */ "double_lqm_rqm",
+        /* 150 */ "double_9qm_lqm",
+        /* 151 */ "double_9qm_rqm",
+        /* 152 */ "more_keys_for_single_quote",
+        /* 153 */ "more_keys_for_double_quote",
+        /* 154 */ "more_keys_for_tablet_double_quote",
+        /* 155 */ "emoji_key_as_more_key",
     };
 
     private static final String EMPTY = "";
@@ -477,7 +479,6 @@
         /* 138 */ ".com",
         // popular web domains for the locale - most popular, displayed on the keyboard
         /* 139 */ "!hasLabels!,.net,.org,.gov,.edu",
-        /* 140 */ "!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ ",
         // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
         // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
         // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
@@ -499,25 +500,25 @@
         // The following each quotation mark pair consist of
         // <opening quotation mark>, <closing quotation mark>
         // and is named after (single|double)_<opening quotation mark>_<closing quotation mark>.
-        /* 141 */ "\u2039,\u203A",
-        /* 142 */ "\u2039|\u203A,\u203A|\u2039",
-        /* 143 */ "\u203A,\u2039",
-        /* 144 */ "\u00AB,\u00BB",
-        /* 145 */ "\u00AB|\u00BB,\u00BB|\u00AB",
-        /* 146 */ "\u00BB,\u00AB",
+        /* 140 */ "\u2039,\u203A",
+        /* 141 */ "\u2039|\u203A,\u203A|\u2039",
+        /* 142 */ "\u203A,\u2039",
+        /* 143 */ "\u00AB,\u00BB",
+        /* 144 */ "\u00AB|\u00BB,\u00BB|\u00AB",
+        /* 145 */ "\u00BB,\u00AB",
         // The following each quotation mark triplet consists of
         // <another quotation mark>, <opening quotation mark>, <closing quotation mark>
         // and is named after (single|double)_<opening quotation mark>_<closing quotation mark>.
-        /* 147 */ "\u201A,\u2018,\u2019",
-        /* 148 */ "\u2019,\u201A,\u2018",
-        /* 149 */ "\u2018,\u201A,\u2019",
-        /* 150 */ "\u201E,\u201C,\u201D",
-        /* 151 */ "\u201D,\u201E,\u201C",
-        /* 152 */ "\u201C,\u201E,\u201D",
-        /* 153 */ "!fixedColumnOrder!5,!text/single_quotes,!text/single_angle_quotes",
-        /* 154 */ "!fixedColumnOrder!5,!text/double_quotes,!text/double_angle_quotes",
-        /* 155 */ "!fixedColumnOrder!6,!text/double_quotes,!text/single_quotes,!text/double_angle_quotes,!text/single_angle_quotes",
-        /* 156 */ "!icon/emoji_key|!code/key_emoji",
+        /* 146 */ "\u201A,\u2018,\u2019",
+        /* 147 */ "\u2019,\u201A,\u2018",
+        /* 148 */ "\u2018,\u201A,\u2019",
+        /* 149 */ "\u201E,\u201C,\u201D",
+        /* 150 */ "\u201D,\u201E,\u201C",
+        /* 151 */ "\u201C,\u201E,\u201D",
+        /* 152 */ "!fixedColumnOrder!5,!text/single_quotes,!text/single_angle_quotes",
+        /* 153 */ "!fixedColumnOrder!5,!text/double_quotes,!text/double_angle_quotes",
+        /* 154 */ "!fixedColumnOrder!6,!text/double_quotes,!text/single_quotes,!text/double_angle_quotes,!text/single_angle_quotes",
+        /* 155 */ "!icon/emoji_key|!code/key_emoji",
     };
 
     /* Language af: Afrikaans */
@@ -3649,7 +3650,7 @@
         for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
             final String language = (String)LANGUAGES_AND_TEXTS[i];
             final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
-            sLocaleToTextsMap.put(language, texts);
+            sLanguageToTextsMap.put(language, texts);
         }
     }
 }
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index b20bcd1..013f922 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -26,12 +26,12 @@
 import com.android.inputmethod.latin.makedict.FormatSpec;
 import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
+import com.android.inputmethod.latin.makedict.WordProperty;
 import com.android.inputmethod.latin.settings.NativeSuggestOptions;
 import com.android.inputmethod.latin.utils.CollectionUtils;
 import com.android.inputmethod.latin.utils.JniUtils;
 import com.android.inputmethod.latin.utils.LanguageModelParam;
 import com.android.inputmethod.latin.utils.StringUtils;
-import com.android.inputmethod.latin.utils.WordProperty;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -217,9 +217,8 @@
                     outAttributeValues.get(i));
             attributes.put(attributeKey, attributeValue);
         }
-        final boolean hasHistoricalInfo =
-                attributes.get(DictionaryHeader.HAS_HISTORICAL_INFO_KEY).equals(
-                        DictionaryHeader.ATTRIBUTE_VALUE_TRUE);
+        final boolean hasHistoricalInfo = DictionaryHeader.ATTRIBUTE_VALUE_TRUE.equals(
+                attributes.get(DictionaryHeader.HAS_HISTORICAL_INFO_KEY));
         return new DictionaryHeader(outHeaderSize[0], new DictionaryOptions(attributes),
                 new FormatSpec.FormatOptions(outFormatVersion[0], hasHistoricalInfo));
     }
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
index e68c6b7..259c137 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
@@ -430,12 +430,19 @@
     public void getSuggestions(final WordComposer composer,
             final String prevWord, final ProximityInfo proximityInfo,
             final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
-            final int sessionId, final Set<SuggestedWordInfo> suggestionSet) {
+            final int sessionId, final Set<SuggestedWordInfo> suggestionSet,
+            final ArrayList<SuggestedWordInfo> rawSuggestions) {
         for (final String key : mDictionaries.keySet()) {
             final Dictionary dictionary = mDictionaries.get(key);
             if (null == dictionary) continue;
-            suggestionSet.addAll(dictionary.getSuggestionsWithSessionId(composer, prevWord,
-                    proximityInfo, blockOffensiveWords, additionalFeaturesOptions, sessionId));
+            final ArrayList<SuggestedWordInfo> dictionarySuggestions =
+                    dictionary.getSuggestionsWithSessionId(composer, prevWord, proximityInfo,
+                            blockOffensiveWords, additionalFeaturesOptions, sessionId);
+            if (null == dictionarySuggestions) continue;
+            suggestionSet.addAll(dictionarySuggestions);
+            if (null != rawSuggestions) {
+                rawSuggestions.addAll(dictionarySuggestions);
+            }
         }
     }
 
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index 48a6588..c2451ce 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -23,13 +23,15 @@
 import com.android.inputmethod.keyboard.ProximityInfo;
 import com.android.inputmethod.latin.makedict.DictionaryHeader;
 import com.android.inputmethod.latin.makedict.FormatSpec;
+import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
+import com.android.inputmethod.latin.makedict.WordProperty;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 import com.android.inputmethod.latin.utils.AsyncResultHolder;
 import com.android.inputmethod.latin.utils.CollectionUtils;
+import com.android.inputmethod.latin.utils.CombinedFormatUtils;
 import com.android.inputmethod.latin.utils.FileUtils;
 import com.android.inputmethod.latin.utils.LanguageModelParam;
 import com.android.inputmethod.latin.utils.PrioritizedSerialExecutor;
-import com.android.inputmethod.latin.utils.WordProperty;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -785,7 +787,14 @@
         getExecutor(mDictName).execute(new Runnable() {
             @Override
             public void run() {
-                Log.d(TAG, "dictionary=" + mDictName);
+                Log.d(TAG, "Dump dictionary: " + mDictName);
+                try {
+                    final DictionaryHeader header = mBinaryDictionary.getHeader();
+                    Log.d(TAG, CombinedFormatUtils.formatAttributeMap(
+                            header.mDictionaryOptions.mAttributes));
+                } catch (final UnsupportedFormatException e) {
+                    Log.d(TAG, "Cannot fetch header information.", e);
+                }
                 int token = 0;
                 do {
                     final BinaryDictionary.GetNextWordPropertyResult result =
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index e55c08d..3b42772 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -620,6 +620,7 @@
             ResearchLogger.getInstance().onDestroy();
         }
         unregisterReceiver(mDictionaryPackInstallReceiver);
+        unregisterReceiver(mDictionaryDumpBroadcastReceiver);
         PersonalizationDictionarySessionRegistrar.close(this);
         LatinImeLogger.commit();
         LatinImeLogger.onDestroy();
@@ -997,7 +998,7 @@
                 SuggestedWords.getFromApplicationSpecifiedCompletions(
                         applicationSpecifiedCompletions);
         final SuggestedWords suggestedWords = new SuggestedWords(
-                applicationSuggestedWords,
+                applicationSuggestedWords, null /* rawSuggestions */,
                 false /* typedWordValid */,
                 false /* willAutoCorrect */,
                 false /* isPunctuationSuggestions */,
@@ -1417,7 +1418,7 @@
                     ? SuggestedWords.EMPTY : previousSuggestedWords;
             final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
                     SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
-            return new SuggestedWords(typedWordAndPreviousSuggestions,
+            return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
                     false /* typedWordValid */,
                     false /* hasAutoCorrectionCandidate */,
                     false /* isPunctuationSuggestions */,
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index bb938a9..5e74d75 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -20,6 +20,7 @@
 
 import com.android.inputmethod.keyboard.ProximityInfo;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
+import com.android.inputmethod.latin.define.ProductionFlag;
 import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
 import com.android.inputmethod.latin.utils.BoundedTreeSet;
 import com.android.inputmethod.latin.utils.CollectionUtils;
@@ -51,7 +52,6 @@
     private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000;
 
     private static final boolean DBG = LatinImeLogger.sDBG;
-
     public final DictionaryFacilitatorForSuggest mDictionaryFacilitator;
 
     private float mAutoCorrectionThreshold;
@@ -124,9 +124,15 @@
         } else {
             wordComposerForLookup = wordComposer;
         }
+        final ArrayList<SuggestedWordInfo> rawSuggestions;
+        if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
+            rawSuggestions = CollectionUtils.newArrayList();
+        } else {
+            rawSuggestions = null;
+        }
         mDictionaryFacilitator.getSuggestions(wordComposerForLookup, prevWordForBigram,
                 proximityInfo, blockOffensiveWords, additionalFeaturesOptions, SESSION_TYPING,
-                suggestionsSet);
+                suggestionsSet, rawSuggestions);
         final String firstSuggestion;
         final String whitelistedWord;
         if (suggestionsSet.isEmpty()) {
@@ -141,8 +147,6 @@
             }
         }
 
-        // The word can be auto-corrected if it has a whitelist entry that is not itself,
-        // or if it's a 2+ characters non-word (i.e. it's not in the dictionary).
         // We allow auto-correction if we have a whitelisted word, or if the word is not a valid
         // word of more than 1 char, except if the first suggestion is the same as the typed string
         // because in this case if it's strong enough to auto-correct that will mistakenly designate
@@ -217,7 +221,7 @@
             suggestionsList = suggestionsContainer;
         }
 
-        callback.onGetSuggestedWords(new SuggestedWords(suggestionsList,
+        callback.onGetSuggestedWords(new SuggestedWords(suggestionsList, rawSuggestions,
                 // TODO: this first argument is lying. If this is a whitelisted word which is an
                 // actual word, it says typedWordValid = false, which looks wrong. We should either
                 // rename the attribute or change the value.
@@ -237,8 +241,15 @@
             final OnGetSuggestedWordsCallback callback) {
         final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
                 SuggestedWords.MAX_SUGGESTIONS);
+        final ArrayList<SuggestedWordInfo> rawSuggestions;
+        if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
+            rawSuggestions = CollectionUtils.newArrayList();
+        } else {
+            rawSuggestions = null;
+        }
         mDictionaryFacilitator.getSuggestions(wordComposer, prevWordForBigram, proximityInfo,
-                blockOffensiveWords, additionalFeaturesOptions, sessionId, suggestionsSet);
+                blockOffensiveWords, additionalFeaturesOptions, sessionId, suggestionsSet,
+                rawSuggestions);
         for (SuggestedWordInfo wordInfo : suggestionsSet) {
             LatinImeLogger.onAddSuggestedWord(wordInfo.mWord, wordInfo.mSourceDict.mDictType);
         }
@@ -275,7 +286,7 @@
 
         // In the batch input mode, the most relevant suggested word should act as a "typed word"
         // (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false).
-        callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer,
+        callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer, rawSuggestions,
                 true /* typedWordValid */,
                 false /* willAutoCorrect */,
                 false /* isPunctuationSuggestions */,
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index dbaf822..b2efc4a 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -37,7 +37,7 @@
     private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST =
             CollectionUtils.newArrayList(0);
     public static final SuggestedWords EMPTY = new SuggestedWords(
-            EMPTY_WORD_INFO_LIST, false, false, false, false, false);
+            EMPTY_WORD_INFO_LIST, null /* rawSuggestions */, false, false, false, false, false);
 
     public final String mTypedWord;
     public final boolean mTypedWordValid;
@@ -50,25 +50,29 @@
     public final boolean mIsPrediction;
     public final int mSequenceNumber; // Sequence number for auto-commit.
     private final ArrayList<SuggestedWordInfo> mSuggestedWordInfoList;
+    public final ArrayList<SuggestedWordInfo> mRawSuggestions;
 
     public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
+            final ArrayList<SuggestedWordInfo> rawSuggestions,
             final boolean typedWordValid,
             final boolean willAutoCorrect,
             final boolean isPunctuationSuggestions,
             final boolean isObsoleteSuggestions,
             final boolean isPrediction) {
-        this(suggestedWordInfoList, typedWordValid, willAutoCorrect, isPunctuationSuggestions,
-                isObsoleteSuggestions, isPrediction, NOT_A_SEQUENCE_NUMBER);
+        this(suggestedWordInfoList, rawSuggestions, typedWordValid, willAutoCorrect,
+                isPunctuationSuggestions, isObsoleteSuggestions, isPrediction,
+                NOT_A_SEQUENCE_NUMBER);
     }
 
     public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
+            final ArrayList<SuggestedWordInfo> rawSuggestions,
             final boolean typedWordValid,
             final boolean willAutoCorrect,
             final boolean isPunctuationSuggestions,
             final boolean isObsoleteSuggestions,
             final boolean isPrediction,
             final int sequenceNumber) {
-        this(suggestedWordInfoList,
+        this(suggestedWordInfoList, rawSuggestions,
                 suggestedWordInfoList.isEmpty() ? null
                         : suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
                 typedWordValid, willAutoCorrect, isPunctuationSuggestions,
@@ -76,6 +80,7 @@
     }
 
     public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
+            final ArrayList<SuggestedWordInfo> rawSuggestions,
             final String typedWord,
             final boolean typedWordValid,
             final boolean willAutoCorrect,
@@ -84,6 +89,7 @@
             final boolean isPrediction,
             final int sequenceNumber) {
         mSuggestedWordInfoList = suggestedWordInfoList;
+        mRawSuggestions = rawSuggestions;
         mTypedWordValid = typedWordValid;
         mWillAutoCorrect = willAutoCorrect;
         mIsPunctuationSuggestions = isPunctuationSuggestions;
@@ -306,9 +312,9 @@
         }
         // We should never autocorrect, so we say the typed word is valid. Also, in this case,
         // no auto-correction should take place hence willAutoCorrect = false.
-        return new SuggestedWords(newSuggestions, typedWord, true /* typedWordValid */,
-                false /* willAutoCorrect */, mIsPunctuationSuggestions, mIsObsoleteSuggestions,
-                mIsPrediction, NOT_A_SEQUENCE_NUMBER);
+        return new SuggestedWords(newSuggestions, null /* rawSuggestions */, typedWord,
+                true /* typedWordValid */, false /* willAutoCorrect */, mIsPunctuationSuggestions,
+                mIsObsoleteSuggestions, mIsPrediction, NOT_A_SEQUENCE_NUMBER);
     }
 
     // Creates a new SuggestedWordInfo from the currently suggested words that removes all but the
@@ -326,7 +332,7 @@
                     info.mSourceDict, SuggestedWordInfo.NOT_AN_INDEX,
                     SuggestedWordInfo.NOT_A_CONFIDENCE));
         }
-        return new SuggestedWords(newSuggestions, mTypedWordValid,
+        return new SuggestedWords(newSuggestions, null /* rawSuggestions */, mTypedWordValid,
                 mWillAutoCorrect, mIsPunctuationSuggestions, mIsObsoleteSuggestions,
                 mIsPrediction);
     }
diff --git a/java/src/com/android/inputmethod/latin/define/ProductionFlag.java b/java/src/com/android/inputmethod/latin/define/ProductionFlag.java
index dc937fb..e6fa1cd 100644
--- a/java/src/com/android/inputmethod/latin/define/ProductionFlag.java
+++ b/java/src/com/android/inputmethod/latin/define/ProductionFlag.java
@@ -29,4 +29,7 @@
     public static final boolean USES_DEVELOPMENT_ONLY_DIAGNOSTICS_DEBUG = false;
 
     public static final boolean IS_HARDWARE_KEYBOARD_SUPPORTED = false;
+
+    // Include all suggestions from all dictionaries in {@link SuggestedWords#mRawSuggestions}.
+    public static final boolean INCLUDE_RAW_SUGGESTIONS = false;
 }
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 3ecf5f0..6e90505 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -1332,7 +1332,8 @@
         } else {
             // We found suggestion spans in the word. We'll create the SuggestedWords out of
             // them, and make willAutoCorrect false.
-            final SuggestedWords suggestedWords = new SuggestedWords(suggestions, typedWord,
+            final SuggestedWords suggestedWords = new SuggestedWords(suggestions,
+                    null /* rawSuggestions */, typedWord,
                     true /* typedWordValid */, false /* willAutoCorrect */,
                     false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
                     false /* isPrediction */, SuggestedWords.NOT_A_SEQUENCE_NUMBER);
diff --git a/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
index 5c7c4b8..e7d1c98 100644
--- a/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java
@@ -22,6 +22,7 @@
 import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -223,4 +224,49 @@
     public boolean hasValidRawBinaryDictionary() {
         return checkHeader() == SUCCESS;
     }
+
+    // Placeholder implementations below. These are actually unused.
+    @Override
+    public void openDictBuffer() throws FileNotFoundException, IOException,
+            UnsupportedFormatException {
+    }
+
+    @Override
+    public boolean isDictBufferOpen() {
+        return false;
+    }
+
+    @Override
+    public PtNodeInfo readPtNode(final int ptNodePos, final FormatOptions options) {
+        return null;
+    }
+
+    @Override
+    public void setPosition(int newPos) {
+    }
+
+    @Override
+    public int getPosition() {
+        return 0;
+    }
+
+    @Override
+    public int readPtNodeCount() {
+        return 0;
+    }
+
+    @Override
+    public boolean readAndFollowForwardLink() {
+        return false;
+    }
+
+    @Override
+    public boolean hasNextPtNodeArray() {
+        return false;
+    }
+
+    @Override
+    @UsedForTesting
+    public void skipPtNode(final FormatOptions formatOptions) {
+    }
 }
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
index 9f23459..782ada3 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
@@ -606,19 +606,21 @@
 
         FusionDictionary newDict = new FusionDictionary(root, fileHeader.mDictionaryOptions);
         if (null != dict) {
-            for (final Word w : dict) {
-                if (w.mIsBlacklistEntry) {
-                    newDict.addBlacklistEntry(w.mWord, w.mShortcutTargets, w.mIsNotAWord);
+            for (final WordProperty wordProperty : dict) {
+                if (wordProperty.mIsBlacklistEntry) {
+                    newDict.addBlacklistEntry(wordProperty.mWord, wordProperty.mShortcutTargets,
+                            wordProperty.mIsNotAWord);
                 } else {
-                    newDict.add(w.mWord, w.mFrequency, w.mShortcutTargets, w.mIsNotAWord);
+                    newDict.add(wordProperty.mWord, wordProperty.getProbability(),
+                            wordProperty.mShortcutTargets, wordProperty.mIsNotAWord);
                 }
             }
-            for (final Word w : dict) {
+            for (final WordProperty wordProperty : dict) {
                 // By construction a binary dictionary may not have bigrams pointing to
                 // words that are not also registered as unigrams so we don't have to avoid
                 // them explicitly here.
-                for (final WeightedString bigram : w.mBigrams) {
-                    newDict.setBigram(w.mWord, bigram.mWord, bigram.getProbability());
+                for (final WeightedString bigram : wordProperty.mBigrams) {
+                    newDict.setBigram(wordProperty.mWord, bigram.mWord, bigram.getProbability());
                 }
             }
         }
diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
index ef23acb..ca4a2e9 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
@@ -31,7 +31,7 @@
  * A dictionary that can fusion heads and tails of words for more compression.
  */
 @UsedForTesting
-public final class FusionDictionary implements Iterable<Word> {
+public final class FusionDictionary implements Iterable<WordProperty> {
     private static final boolean DBG = MakedictLog.DBG;
 
     private static int CHARACTER_NOT_FOUND_INDEX = -1;
@@ -76,8 +76,12 @@
         public ProbabilityInfo mProbabilityInfo;
 
         public WeightedString(final String word, final int probability) {
+            this(word, new ProbabilityInfo(probability));
+        }
+
+        public WeightedString(final String word, final ProbabilityInfo probabilityInfo) {
             mWord = word;
-            mProbabilityInfo = new ProbabilityInfo(probability);
+            mProbabilityInfo = probabilityInfo;
         }
 
         public int getProbability() {
@@ -90,9 +94,7 @@
 
         @Override
         public int hashCode() {
-            return Arrays.hashCode(new Object[] { mWord, mProbabilityInfo.mProbability,
-                    mProbabilityInfo.mTimestamp, mProbabilityInfo.mLevel,
-                    mProbabilityInfo.mCount });
+            return Arrays.hashCode(new Object[] { mWord, mProbabilityInfo});
         }
 
         @Override
@@ -434,25 +436,25 @@
     /**
      * Helper method to add a new bigram to the dictionary.
      *
-     * @param word1 the previous word of the context
-     * @param word2 the next word of the context
+     * @param word0 the previous word of the context
+     * @param word1 the next word of the context
      * @param frequency the bigram frequency
      */
-    public void setBigram(final String word1, final String word2, final int frequency) {
-        PtNode ptNode = findWordInTree(mRootNodeArray, word1);
-        if (ptNode != null) {
-            final PtNode ptNode2 = findWordInTree(mRootNodeArray, word2);
-            if (ptNode2 == null) {
-                add(getCodePoints(word2), 0, null, false /* isNotAWord */,
+    public void setBigram(final String word0, final String word1, final int frequency) {
+        PtNode ptNode0 = findWordInTree(mRootNodeArray, word0);
+        if (ptNode0 != null) {
+            final PtNode ptNode1 = findWordInTree(mRootNodeArray, word1);
+            if (ptNode1 == null) {
+                add(getCodePoints(word1), 0, null, false /* isNotAWord */,
                         false /* isBlacklistEntry */);
                 // The PtNode for the first word may have moved by the above insertion,
                 // if word1 and word2 share a common stem that happens not to have been
                 // a cutting point until now. In this case, we need to refresh ptNode.
-                ptNode = findWordInTree(mRootNodeArray, word1);
+                ptNode0 = findWordInTree(mRootNodeArray, word0);
             }
-            ptNode.addBigram(word2, frequency);
+            ptNode0.addBigram(word1, frequency);
         } else {
-            throw new RuntimeException("First word of bigram not found");
+            throw new RuntimeException("First word of bigram not found " + word0);
         }
     }
 
@@ -704,7 +706,7 @@
      *
      * This is purely for convenience.
      */
-    public static final class DictionaryIterator implements Iterator<Word> {
+    public static final class DictionaryIterator implements Iterator<WordProperty> {
         private static final class Position {
             public Iterator<PtNode> pos;
             public int length;
@@ -734,7 +736,7 @@
         }
 
         @Override
-        public Word next() {
+        public WordProperty next() {
             Position currentPos = mPositions.getLast();
             mCurrentString.setLength(currentPos.length);
 
@@ -751,7 +753,7 @@
                         mPositions.addLast(currentPos);
                     }
                     if (currentPtNode.mFrequency >= 0) {
-                        return new Word(mCurrentString.toString(), currentPtNode.mFrequency,
+                        return new WordProperty(mCurrentString.toString(), currentPtNode.mFrequency,
                                 currentPtNode.mShortcutTargets, currentPtNode.mBigrams,
                                 currentPtNode.mIsNotAWord, currentPtNode.mIsBlacklistEntry);
                     }
@@ -777,7 +779,7 @@
      * and say : for (Word w : x) {}
      */
     @Override
-    public Iterator<Word> iterator() {
+    public Iterator<WordProperty> iterator() {
         return new DictionaryIterator(mRootNodeArray.mData);
     }
 }
diff --git a/java/src/com/android/inputmethod/latin/makedict/ProbabilityInfo.java b/java/src/com/android/inputmethod/latin/makedict/ProbabilityInfo.java
index 79f924c..dafbc04 100644
--- a/java/src/com/android/inputmethod/latin/makedict/ProbabilityInfo.java
+++ b/java/src/com/android/inputmethod/latin/makedict/ProbabilityInfo.java
@@ -17,7 +17,9 @@
 package com.android.inputmethod.latin.makedict;
 
 import com.android.inputmethod.latin.BinaryDictionary;
-import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
+import com.android.inputmethod.latin.utils.CombinedFormatUtils;
+
+import java.util.Arrays;
 
 public final class ProbabilityInfo {
     public final int mProbability;
@@ -45,19 +47,28 @@
     }
 
     @Override
+    public int hashCode() {
+        if (hasHistoricalInfo()) {
+            return Arrays.hashCode(new Object[] { mProbability, mTimestamp, mLevel, mCount });
+        } else {
+            return Arrays.hashCode(new Object[] { mProbability });
+        }
+    }
+
+    @Override
     public String toString() {
-        return mTimestamp + ":" + mLevel + ":" + mCount;
+        return CombinedFormatUtils.formatProbabilityInfo(this);
     }
 
     @Override
     public boolean equals(Object o) {
-      if (o == this) return true;
-      if (!(o instanceof ProbabilityInfo)) return false;
-      final ProbabilityInfo p = (ProbabilityInfo)o;
-      if (!hasHistoricalInfo() && !p.hasHistoricalInfo()) {
-          return mProbability == p.mProbability;
-      }
-      return mProbability == p.mProbability && mTimestamp == p.mTimestamp && mLevel == p.mLevel
-              && mCount == p.mCount;
-  }
+        if (o == this) return true;
+        if (!(o instanceof ProbabilityInfo)) return false;
+        final ProbabilityInfo p = (ProbabilityInfo)o;
+        if (!hasHistoricalInfo() && !p.hasHistoricalInfo()) {
+            return mProbability == p.mProbability;
+        }
+        return mProbability == p.mProbability && mTimestamp == p.mTimestamp && mLevel == p.mLevel
+                && mCount == p.mCount;
+    }
 }
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/latin/makedict/SparseTable.java b/java/src/com/android/inputmethod/latin/makedict/SparseTable.java
deleted file mode 100644
index 7592a0c..0000000
--- a/java/src/com/android/inputmethod/latin/makedict/SparseTable.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.latin.makedict;
-
-import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.utils.CollectionUtils;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-
-/**
- * SparseTable is an extensible map from integer to integer.
- * This holds one value for every mBlockSize keys, so it uses 1/mBlockSize'th of the full index
- * memory.
- */
-@UsedForTesting
-public class SparseTable {
-
-    /**
-     * mLookupTable is indexed by terminal ID, containing exactly one entry for every mBlockSize
-     * terminals.
-     * It contains at index i = j / mBlockSize the index in each ArrayList in mContentsTables where
-     * the values for terminals with IDs j to j + mBlockSize - 1 are stored as an mBlockSize-sized
-     * integer array.
-     */
-    private final ArrayList<Integer> mLookupTable;
-    private final ArrayList<ArrayList<Integer>> mContentTables;
-
-    private final int mBlockSize;
-    private final int mContentTableCount;
-    public static final int NOT_EXIST = -1;
-    public static final int SIZE_OF_INT_IN_BYTES = 4;
-
-    @UsedForTesting
-    public SparseTable(final int initialCapacity, final int blockSize,
-            final int contentTableCount) {
-        mBlockSize = blockSize;
-        final int lookupTableSize = initialCapacity / mBlockSize
-                + (initialCapacity % mBlockSize > 0 ? 1 : 0);
-        mLookupTable = new ArrayList<Integer>(Collections.nCopies(lookupTableSize, NOT_EXIST));
-        mContentTableCount = contentTableCount;
-        mContentTables = CollectionUtils.newArrayList();
-        for (int i = 0; i < mContentTableCount; ++i) {
-            mContentTables.add(new ArrayList<Integer>());
-        }
-    }
-
-    @UsedForTesting
-    public SparseTable(final ArrayList<Integer> lookupTable,
-            final ArrayList<ArrayList<Integer>> contentTables, final int blockSize) {
-        mBlockSize = blockSize;
-        mContentTableCount = contentTables.size();
-        mLookupTable = lookupTable;
-        mContentTables = contentTables;
-    }
-
-    /**
-     * Converts an byte array to an int array considering each set of 4 bytes is an int stored in
-     * big-endian.
-     * The length of byteArray must be a multiple of four.
-     * Otherwise, IndexOutOfBoundsException will be raised.
-     */
-    @UsedForTesting
-    private static ArrayList<Integer> convertByteArrayToIntegerArray(final byte[] byteArray) {
-        final ArrayList<Integer> integerArray = new ArrayList<Integer>(byteArray.length / 4);
-        for (int i = 0; i < byteArray.length; i += 4) {
-            int value = 0;
-            for (int j = i; j < i + 4; ++j) {
-                value <<= 8;
-                value |= byteArray[j] & 0xFF;
-             }
-            integerArray.add(value);
-        }
-        return integerArray;
-    }
-
-    @UsedForTesting
-    public int get(final int contentTableIndex, final int index) {
-        if (!contains(index)) {
-            return NOT_EXIST;
-        }
-        return mContentTables.get(contentTableIndex).get(
-                mLookupTable.get(index / mBlockSize) + (index % mBlockSize));
-    }
-
-    @UsedForTesting
-    public ArrayList<Integer> getAll(final int index) {
-        final ArrayList<Integer> ret = CollectionUtils.newArrayList();
-        for (int i = 0; i < mContentTableCount; ++i) {
-            ret.add(get(i, index));
-        }
-        return ret;
-    }
-
-    @UsedForTesting
-    public void set(final int contentTableIndex, final int index, final int value) {
-        if (mLookupTable.get(index / mBlockSize) == NOT_EXIST) {
-            mLookupTable.set(index / mBlockSize, mContentTables.get(contentTableIndex).size());
-            for (int i = 0; i < mContentTableCount; ++i) {
-                for (int j = 0; j < mBlockSize; ++j) {
-                    mContentTables.get(i).add(NOT_EXIST);
-                }
-            }
-        }
-        mContentTables.get(contentTableIndex).set(
-                mLookupTable.get(index / mBlockSize) + (index % mBlockSize), value);
-    }
-
-    public void remove(final int indexOfContent, final int index) {
-        set(indexOfContent, index, NOT_EXIST);
-    }
-
-    @UsedForTesting
-    public int size() {
-        return mLookupTable.size() * mBlockSize;
-    }
-
-    @UsedForTesting
-    /* package */ int getContentTableSize() {
-        // This class always has at least one content table.
-        return mContentTables.get(0).size();
-    }
-
-    @UsedForTesting
-    /* package */ int getLookupTableSize() {
-        return mLookupTable.size();
-    }
-
-    public boolean contains(final int index) {
-        if (index < 0 || index / mBlockSize >= mLookupTable.size()
-                || mLookupTable.get(index / mBlockSize) == NOT_EXIST) {
-            return false;
-        }
-        return true;
-    }
-
-    @UsedForTesting
-    public void write(final OutputStream lookupOutStream, final OutputStream[] contentOutStreams)
-            throws IOException {
-         if (contentOutStreams.length != mContentTableCount) {
-             throw new RuntimeException(contentOutStreams.length + " streams are given, but the"
-                     + " table has " + mContentTableCount + " content tables.");
-         }
-        for (final int index : mLookupTable) {
-          BinaryDictEncoderUtils.writeUIntToStream(lookupOutStream, index, SIZE_OF_INT_IN_BYTES);
-        }
-
-        for (int i = 0; i < contentOutStreams.length; ++i) {
-            for (final int data : mContentTables.get(i)) {
-                BinaryDictEncoderUtils.writeUIntToStream(contentOutStreams[i], data,
-                        SIZE_OF_INT_IN_BYTES);
-            }
-        }
-    }
-
-    @UsedForTesting
-    public void writeToFiles(final File lookupTableFile, final File[] contentFiles)
-            throws IOException {
-        FileOutputStream lookupTableOutStream = null;
-        final FileOutputStream[] contentTableOutStreams = new FileOutputStream[mContentTableCount];
-        try {
-            lookupTableOutStream = new FileOutputStream(lookupTableFile);
-            for (int i = 0; i < contentFiles.length; ++i) {
-                contentTableOutStreams[i] = new FileOutputStream(contentFiles[i]);
-            }
-            write(lookupTableOutStream, contentTableOutStreams);
-        } finally {
-            if (lookupTableOutStream != null) {
-                lookupTableOutStream.close();
-            }
-            for (int i = 0; i < contentTableOutStreams.length; ++i) {
-                if (contentTableOutStreams[i] != null) {
-                    contentTableOutStreams[i].close();
-                }
-            }
-        }
-    }
-
-    private static byte[] readFileToByteArray(final File file) throws IOException {
-        final byte[] contents = new byte[(int) file.length()];
-        FileInputStream inStream = null;
-        try {
-            inStream = new FileInputStream(file);
-            inStream.read(contents);
-        } finally {
-            if (inStream != null) {
-                inStream.close();
-            }
-        }
-        return contents;
-    }
-
-    @UsedForTesting
-    public static SparseTable readFromFiles(final File lookupTableFile, final File[] contentFiles,
-            final int blockSize) throws IOException {
-        final ArrayList<ArrayList<Integer>> contentTables =
-                new ArrayList<ArrayList<Integer>>(contentFiles.length);
-        for (int i = 0; i < contentFiles.length; ++i) {
-            contentTables.add(convertByteArrayToIntegerArray(readFileToByteArray(contentFiles[i])));
-        }
-        return new SparseTable(convertByteArrayToIntegerArray(readFileToByteArray(lookupTableFile)),
-                contentTables, blockSize);
-    }
-}
diff --git a/java/src/com/android/inputmethod/latin/makedict/SparseTableContentReader.java b/java/src/com/android/inputmethod/latin/makedict/SparseTableContentReader.java
deleted file mode 100644
index 63e1f56..0000000
--- a/java/src/com/android/inputmethod/latin/makedict/SparseTableContentReader.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.latin.makedict;
-
-import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
-import com.android.inputmethod.latin.makedict.DictDecoder.DictionaryBufferFactory;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-/**
- * An auxiliary class for reading SparseTable and data written by SparseTableContentWriter.
- */
-public class SparseTableContentReader {
-
-    /**
-     * An interface of a function which is passed to SparseTableContentReader.read.
-     */
-    public interface SparseTableContentReaderInterface {
-        /**
-         * Reads data.
-         *
-         * @param buffer the DictBuffer. The position of the buffer is set to the head of data.
-         */
-        public void read(final DictBuffer buffer);
-    }
-
-    protected final int mContentCount;
-    protected final int mBlockSize;
-    protected final File mBaseDir;
-    protected final File mLookupTableFile;
-    protected final File[] mAddressTableFiles;
-    protected final File[] mContentFiles;
-    protected DictBuffer mLookupTableBuffer;
-    protected final DictBuffer[] mAddressTableBuffers;
-    private final DictBuffer[] mContentBuffers;
-    protected final DictionaryBufferFactory mFactory;
-
-    /**
-     * Sole constructor of SparseTableContentReader.
-     *
-     * @param name the name of SparseTable.
-     * @param blockSize the block size of the content table.
-     * @param baseDir the directory which contains the files of the content table.
-     * @param contentFilenames the file names of content files.
-     * @param contentSuffixes the ids of contents. These ids are used for a suffix of a name of
-     * address files and content files.
-     * @param factory the DictionaryBufferFactory which is used for opening the files.
-     */
-    public SparseTableContentReader(final String name, final int blockSize, final File baseDir,
-            final String[] contentFilenames, final String[] contentSuffixes,
-            final DictionaryBufferFactory factory) {
-        if (contentFilenames.length != contentSuffixes.length) {
-            throw new RuntimeException("The length of contentFilenames and the length of"
-                    + " contentSuffixes are different " + contentFilenames.length + ", "
-                    + contentSuffixes.length);
-        }
-        mBlockSize = blockSize;
-        mBaseDir = baseDir;
-        mFactory = factory;
-        mContentCount = contentFilenames.length;
-        mLookupTableFile = new File(baseDir, name + FormatSpec.LOOKUP_TABLE_FILE_SUFFIX);
-        mAddressTableFiles = new File[mContentCount];
-        mContentFiles = new File[mContentCount];
-        for (int i = 0; i < mContentCount; ++i) {
-            mAddressTableFiles[i] = new File(mBaseDir,
-                    name + FormatSpec.CONTENT_TABLE_FILE_SUFFIX + contentSuffixes[i]);
-            mContentFiles[i] = new File(mBaseDir, contentFilenames[i] + contentSuffixes[i]);
-        }
-        mAddressTableBuffers = new DictBuffer[mContentCount];
-        mContentBuffers = new DictBuffer[mContentCount];
-    }
-
-    public void openBuffers() throws FileNotFoundException, IOException {
-        mLookupTableBuffer = mFactory.getDictionaryBuffer(mLookupTableFile);
-        for (int i = 0; i < mContentCount; ++i) {
-            mAddressTableBuffers[i] = mFactory.getDictionaryBuffer(mAddressTableFiles[i]);
-            mContentBuffers[i] = mFactory.getDictionaryBuffer(mContentFiles[i]);
-        }
-    }
-
-    /**
-     * Calls the read() callback of the reader with the appropriate buffer appropriately positioned.
-     * @param contentNumber the index in the original contentFilenames[] array.
-     * @param terminalId the terminal ID to read.
-     * @param reader the reader on which to call the callback.
-     */
-    protected void read(final int contentNumber, final int terminalId,
-            final SparseTableContentReaderInterface reader) {
-        if (terminalId < 0 || (terminalId / mBlockSize) * SparseTable.SIZE_OF_INT_IN_BYTES
-                >= mLookupTableBuffer.limit()) {
-            return;
-        }
-
-        mLookupTableBuffer.position((terminalId / mBlockSize) * SparseTable.SIZE_OF_INT_IN_BYTES);
-        final int indexInAddressTable = mLookupTableBuffer.readInt();
-        if (indexInAddressTable == SparseTable.NOT_EXIST) {
-            return;
-        }
-
-        mAddressTableBuffers[contentNumber].position(SparseTable.SIZE_OF_INT_IN_BYTES
-                * ((indexInAddressTable * mBlockSize) + (terminalId % mBlockSize)));
-        final int address = mAddressTableBuffers[contentNumber].readInt();
-        if (address == SparseTable.NOT_EXIST) {
-            return;
-        }
-
-        mContentBuffers[contentNumber].position(address);
-        reader.read(mContentBuffers[contentNumber]);
-    }
-}
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/latin/makedict/SparseTableContentWriter.java b/java/src/com/android/inputmethod/latin/makedict/SparseTableContentWriter.java
deleted file mode 100644
index 49f0fd6..0000000
--- a/java/src/com/android/inputmethod/latin/makedict/SparseTableContentWriter.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.latin.makedict;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * An auxiliary class for writing data associated with SparseTable to files.
- */
-public class SparseTableContentWriter {
-    public interface SparseTableContentWriterInterface {
-        public void write(final OutputStream outStream) throws IOException;
-    }
-
-    private final int mContentCount;
-    private final SparseTable mSparseTable;
-    private final File mLookupTableFile;
-    protected final File mBaseDir;
-    private final File[] mAddressTableFiles;
-    private final File[] mContentFiles;
-    protected final OutputStream[] mContentOutStreams;
-
-    /**
-     * Sole constructor of SparseTableContentWriter.
-     *
-     * @param name the name of SparseTable.
-     * @param initialCapacity the initial capacity of SparseTable.
-     * @param blockSize the block size of the content table.
-     * @param baseDir the directory which contains the files of the content table.
-     * @param contentFilenames the file names of content files.
-     * @param contentIds the ids of contents. These ids are used for a suffix of a name of address
-     * files and content files.
-     */
-    public SparseTableContentWriter(final String name, final int initialCapacity,
-            final int blockSize, final File baseDir, final String[] contentFilenames,
-            final String[] contentIds) {
-        if (contentFilenames.length != contentIds.length) {
-            throw new RuntimeException("The length of contentFilenames and the length of"
-                    + " contentIds are different " + contentFilenames.length + ", "
-                    + contentIds.length);
-        }
-        mContentCount = contentFilenames.length;
-        mSparseTable = new SparseTable(initialCapacity, blockSize, mContentCount);
-        mLookupTableFile = new File(baseDir, name + FormatSpec.LOOKUP_TABLE_FILE_SUFFIX);
-        mAddressTableFiles = new File[mContentCount];
-        mContentFiles = new File[mContentCount];
-        mBaseDir = baseDir;
-        for (int i = 0; i < mContentCount; ++i) {
-            mAddressTableFiles[i] = new File(mBaseDir,
-                    name + FormatSpec.CONTENT_TABLE_FILE_SUFFIX + contentIds[i]);
-            mContentFiles[i] = new File(mBaseDir, contentFilenames[i] + contentIds[i]);
-        }
-        mContentOutStreams = new OutputStream[mContentCount];
-    }
-
-    public void openStreams() throws FileNotFoundException {
-        for (int i = 0; i < mContentCount; ++i) {
-            mContentOutStreams[i] = new FileOutputStream(mContentFiles[i]);
-        }
-    }
-
-    protected void write(final int contentIndex, final int index,
-            final SparseTableContentWriterInterface writer) throws IOException {
-        mSparseTable.set(contentIndex, index, (int) mContentFiles[contentIndex].length());
-        writer.write(mContentOutStreams[contentIndex]);
-        mContentOutStreams[contentIndex].flush();
-    }
-
-    public void closeStreams() throws IOException {
-        mSparseTable.writeToFiles(mLookupTableFile, mAddressTableFiles);
-        for (int i = 0; i < mContentCount; ++i) {
-            mContentOutStreams[i].close();
-        }
-    }
-}
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
index 9ddaaf7..8370748 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java
@@ -17,20 +17,15 @@
 package com.android.inputmethod.latin.makedict;
 
 import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.CharEncoding;
-import com.android.inputmethod.latin.makedict.BinaryDictDecoderUtils.DictBuffer;
-import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
-import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
+import com.android.inputmethod.latin.BinaryDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
 import com.android.inputmethod.latin.utils.CollectionUtils;
-
-import android.util.Log;
+import com.android.inputmethod.latin.utils.FileUtils;
 
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 
 /**
  * An implementation of binary dictionary decoder for version 4 binary dictionary.
@@ -39,421 +34,74 @@
 public class Ver4DictDecoder extends AbstractDictDecoder {
     private static final String TAG = Ver4DictDecoder.class.getSimpleName();
 
-    protected static final int FILETYPE_TRIE = 1;
-    protected static final int FILETYPE_FREQUENCY = 2;
-    protected static final int FILETYPE_TERMINAL_ADDRESS_TABLE = 3;
-    protected static final int FILETYPE_BIGRAM_FREQ = 4;
-    protected static final int FILETYPE_SHORTCUT = 5;
-    protected static final int FILETYPE_HEADER = 6;
-
-    protected final File mDictDirectory;
-    protected final DictionaryBufferFactory mBufferFactory;
-    protected DictBuffer mDictBuffer;
-    protected DictBuffer mHeaderBuffer;
-    protected DictBuffer mFrequencyBuffer;
-    protected DictBuffer mTerminalAddressTableBuffer;
-    private BigramContentReader mBigramReader;
-    private ShortcutContentReader mShortcutReader;
-
-    /**
-     * Raw PtNode info straight out of a trie file in version 4 dictionary.
-     */
-    protected static final class Ver4PtNodeInfo {
-        public final int mFlags;
-        public final int[] mCharacters;
-        public final int mTerminalId;
-        public final int mChildrenPos;
-        public final int mParentPos;
-        public final int mNodeSize;
-        public int mStartIndexOfCharacters;
-        public int mEndIndexOfCharacters; // exclusive
-
-        public Ver4PtNodeInfo(final int flags, final int[] characters, final int terminalId,
-                final int childrenPos, final int parentPos, final int nodeSize) {
-            mFlags = flags;
-            mCharacters = characters;
-            mTerminalId = terminalId;
-            mChildrenPos = childrenPos;
-            mParentPos = parentPos;
-            mNodeSize = nodeSize;
-            mStartIndexOfCharacters = 0;
-            mEndIndexOfCharacters = characters.length;
-        }
-    }
+    final File mDictDirectory;
+    final BinaryDictionary mBinaryDictionary;
 
     @UsedForTesting
     /* package */ Ver4DictDecoder(final File dictDirectory, final int factoryFlag) {
-        mDictDirectory = dictDirectory;
-        mDictBuffer = mHeaderBuffer = mFrequencyBuffer = null;
-
-        if ((factoryFlag & MASK_DICTBUFFER) == USE_READONLY_BYTEBUFFER) {
-            mBufferFactory = new DictionaryBufferFromReadOnlyByteBufferFactory();
-        } else if ((factoryFlag  & MASK_DICTBUFFER) == USE_BYTEARRAY) {
-            mBufferFactory = new DictionaryBufferFromByteArrayFactory();
-        } else if ((factoryFlag & MASK_DICTBUFFER) == USE_WRITABLE_BYTEBUFFER) {
-            mBufferFactory = new DictionaryBufferFromWritableByteBufferFactory();
-        } else {
-            mBufferFactory = new DictionaryBufferFromReadOnlyByteBufferFactory();
-        }
+        this(dictDirectory, null /* factory */);
     }
 
     @UsedForTesting
     /* package */ Ver4DictDecoder(final File dictDirectory, final DictionaryBufferFactory factory) {
         mDictDirectory = dictDirectory;
-        mBufferFactory = factory;
-        mDictBuffer = mHeaderBuffer = mFrequencyBuffer = null;
-    }
-
-    protected File getFile(final int fileType) throws UnsupportedFormatException {
-        if (fileType == FILETYPE_TRIE) {
-            return new File(mDictDirectory,
-                    mDictDirectory.getName() + FormatSpec.TRIE_FILE_EXTENSION);
-        } else if (fileType == FILETYPE_HEADER) {
-            return new File(mDictDirectory,
-                    mDictDirectory.getName() + FormatSpec.HEADER_FILE_EXTENSION);
-        } else if (fileType == FILETYPE_FREQUENCY) {
-            return new File(mDictDirectory,
-                    mDictDirectory.getName() + FormatSpec.FREQ_FILE_EXTENSION);
-        } else if (fileType == FILETYPE_TERMINAL_ADDRESS_TABLE) {
-            return new File(mDictDirectory,
-                    mDictDirectory.getName() + FormatSpec.TERMINAL_ADDRESS_TABLE_FILE_EXTENSION);
-        } else if (fileType == FILETYPE_BIGRAM_FREQ) {
-            return new File(mDictDirectory,
-                    mDictDirectory.getName() + FormatSpec.BIGRAM_FILE_EXTENSION
-                            + FormatSpec.BIGRAM_FREQ_CONTENT_ID);
-        } else if (fileType == FILETYPE_SHORTCUT) {
-            return new File(mDictDirectory,
-                    mDictDirectory.getName() + FormatSpec.SHORTCUT_FILE_EXTENSION
-                            + FormatSpec.SHORTCUT_CONTENT_ID);
-        } else {
-            throw new UnsupportedFormatException("Unsupported kind of file : " + fileType);
-        }
-    }
-
-    @Override
-    public void openDictBuffer() throws FileNotFoundException, IOException,
-            UnsupportedFormatException {
-        if (!mDictDirectory.isDirectory()) {
-            throw new UnsupportedFormatException("Format 4 dictionary needs a directory");
-        }
-        mHeaderBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_HEADER));
-        mDictBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_TRIE));
-        mFrequencyBuffer = mBufferFactory.getDictionaryBuffer(getFile(FILETYPE_FREQUENCY));
-        mTerminalAddressTableBuffer = mBufferFactory.getDictionaryBuffer(
-                getFile(FILETYPE_TERMINAL_ADDRESS_TABLE));
-        mBigramReader = new BigramContentReader(mDictDirectory.getName(),
-                mDictDirectory, mBufferFactory);
-        mBigramReader.openBuffers();
-        mShortcutReader = new ShortcutContentReader(mDictDirectory.getName(), mDictDirectory,
-                mBufferFactory);
-        mShortcutReader.openBuffers();
-    }
-
-    @Override
-    public boolean isDictBufferOpen() {
-        return mDictBuffer != null;
-    }
-
-    @UsedForTesting
-    /* package */ DictBuffer getHeaderBuffer() {
-        return mHeaderBuffer;
-    }
-
-    @UsedForTesting
-    /* package */ DictBuffer getDictBuffer() {
-        return mDictBuffer;
+        mBinaryDictionary = new BinaryDictionary(dictDirectory.getAbsolutePath(),
+                0 /* offset */, 0 /* length */, true /* useFullEditDistance */, null /* locale */,
+                "" /* dictType */, true /* isUpdatable */);
     }
 
     @Override
     public DictionaryHeader readHeader() throws IOException, UnsupportedFormatException {
-        if (mHeaderBuffer == null) {
-            openDictBuffer();
-        }
-        mHeaderBuffer.position(0);
-        final DictionaryHeader header = super.readHeader(mHeaderBuffer);
-        final int version = header.mFormatOptions.mVersion;
-        if (version != FormatSpec.VERSION4) {
-            throw new UnsupportedFormatException("File header has a wrong version : " + version);
-        }
-        return header;
-    }
-
-    /**
-     * An auxiliary class for reading bigrams.
-     */
-    protected static class BigramContentReader extends SparseTableContentReader {
-        public BigramContentReader(final String name, final File baseDir,
-                final DictionaryBufferFactory factory) {
-            super(name + FormatSpec.BIGRAM_FILE_EXTENSION,
-                    FormatSpec.BIGRAM_ADDRESS_TABLE_BLOCK_SIZE, baseDir,
-                    getContentFilenames(name), getContentIds(), factory);
-        }
-
-        // TODO: Consolidate this method and BigramContentWriter.getContentFilenames.
-        protected static String[] getContentFilenames(final String name) {
-            return new String[] { name + FormatSpec.BIGRAM_FILE_EXTENSION };
-        }
-
-        // TODO: Consolidate this method and BigramContentWriter.getContentIds.
-        protected static String[] getContentIds() {
-            return new String[] { FormatSpec.BIGRAM_FREQ_CONTENT_ID };
-        }
-
-        public ArrayList<PendingAttribute> readTargetsAndFrequencies(final int terminalId,
-                final DictBuffer terminalAddressTableBuffer, final FormatOptions options) {
-            final ArrayList<PendingAttribute> bigrams = CollectionUtils.newArrayList();
-            read(FormatSpec.BIGRAM_FREQ_CONTENT_INDEX, terminalId,
-                    new SparseTableContentReaderInterface() {
-                        @Override
-                        public void read(final DictBuffer buffer) {
-                            while (bigrams.size() < FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) {
-                                // If bigrams.size() reaches FormatSpec.MAX_BIGRAMS_IN_A_PTNODE,
-                                // remaining bigram entries are ignored.
-                                final int bigramFlags = buffer.readUnsignedByte();
-                                final int probability;
-
-                                if (options.mHasTimestamp) {
-                                    probability = buffer.readUnsignedByte();
-                                    // Skip timestamp
-                                    buffer.readInt();
-                                    // Skip level
-                                    buffer.readUnsignedByte();
-                                    // Skip count
-                                    buffer.readUnsignedByte();
-                                } else {
-                                    probability = bigramFlags
-                                            & FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_FREQUENCY;
-                                }
-                                final int targetTerminalId = buffer.readUnsignedInt24();
-                                terminalAddressTableBuffer.position(targetTerminalId
-                                        * FormatSpec.TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE);
-                                final int targetAddress =
-                                        terminalAddressTableBuffer.readUnsignedInt24();
-                                bigrams.add(new PendingAttribute(probability, targetAddress));
-                                if (0 == (bigramFlags
-                                        & FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_HAS_NEXT)) {
-                                    break;
-                                }
-                            }
-                            if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_PTNODE) {
-                                throw new RuntimeException("Too many bigrams in a PtNode ("
-                                        + bigrams.size() + " but max is "
-                                        + FormatSpec.MAX_BIGRAMS_IN_A_PTNODE + ")");
-                            }
-                        }
-                    });
-            if (bigrams.isEmpty()) return null;
-            return bigrams;
-        }
-    }
-
-    /**
-     * An auxiliary class for reading shortcuts.
-     */
-    protected static class ShortcutContentReader extends SparseTableContentReader {
-        public ShortcutContentReader(final String name, final File baseDir,
-                final DictionaryBufferFactory factory) {
-            super(name + FormatSpec.SHORTCUT_FILE_EXTENSION,
-                    FormatSpec.SHORTCUT_ADDRESS_TABLE_BLOCK_SIZE, baseDir,
-                    new String[] { name + FormatSpec.SHORTCUT_FILE_EXTENSION },
-                    new String[] { FormatSpec.SHORTCUT_CONTENT_ID }, factory);
-        }
-
-        public ArrayList<WeightedString> readShortcuts(final int terminalId) {
-            final ArrayList<WeightedString> shortcuts = CollectionUtils.newArrayList();
-            read(FormatSpec.SHORTCUT_CONTENT_INDEX, terminalId,
-                    new SparseTableContentReaderInterface() {
-                        @Override
-                        public void read(final DictBuffer buffer) {
-                            while (true) {
-                                final int flags = buffer.readUnsignedByte();
-                                final String word = CharEncoding.readString(buffer);
-                                shortcuts.add(new WeightedString(word,
-                                        flags & FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_FREQUENCY));
-                                if (0 == (flags & FormatSpec.FLAG_BIGRAM_SHORTCUT_ATTR_HAS_NEXT)) {
-                                    break;
-                                }
-                            }
-                        }
-                    });
-            if (shortcuts.isEmpty()) return null;
-            return shortcuts;
-        }
-    }
-
-    protected static class PtNodeReader extends AbstractDictDecoder.PtNodeReader {
-        protected static int readFrequency(final DictBuffer frequencyBuffer, final int terminalId,
-                final FormatOptions formatOptions) {
-            final int readingPos;
-            if (formatOptions.mHasTimestamp) {
-                final int entrySize = FormatSpec.FREQUENCY_AND_FLAGS_SIZE
-                        + FormatSpec.UNIGRAM_TIMESTAMP_SIZE + FormatSpec.UNIGRAM_LEVEL_SIZE
-                        + FormatSpec.UNIGRAM_COUNTER_SIZE;
-                readingPos = terminalId * entrySize + FormatSpec.FLAGS_IN_FREQ_FILE_SIZE;
-            } else {
-                readingPos = terminalId * FormatSpec.FREQUENCY_AND_FLAGS_SIZE
-                        + FormatSpec.FLAGS_IN_FREQ_FILE_SIZE;
-            }
-            frequencyBuffer.position(readingPos);
-            return frequencyBuffer.readUnsignedByte();
-        }
-
-        protected static int readTerminalId(final DictBuffer dictBuffer) {
-            return dictBuffer.readInt();
-        }
-    }
-
-    private final int[] mCharacterBufferForReadingVer4PtNodeInfo
-            = new int[FormatSpec.MAX_WORD_LENGTH];
-
-    /**
-     * Reads PtNode from ptNodePos in the trie file and returns Ver4PtNodeInfo.
-     *
-     * @param ptNodePos the position of PtNode.
-     * @param options the format options.
-     * @return Ver4PtNodeInfo.
-     */
-    // TODO: Make this buffer thread safe.
-    // TODO: Support words longer than FormatSpec.MAX_WORD_LENGTH.
-    protected Ver4PtNodeInfo readVer4PtNodeInfo(final int ptNodePos, final FormatOptions options) {
-        int readingPos = ptNodePos;
-        final int flags = PtNodeReader.readPtNodeOptionFlags(mDictBuffer);
-        readingPos += FormatSpec.PTNODE_FLAGS_SIZE;
-
-        final int parentPos = PtNodeReader.readParentAddress(mDictBuffer, options);
-        if (BinaryDictIOUtils.supportsDynamicUpdate(options)) {
-            readingPos += FormatSpec.PARENT_ADDRESS_SIZE;
-        }
-
-        final int characters[];
-        if (0 != (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS)) {
-            int index = 0;
-            int character = CharEncoding.readChar(mDictBuffer);
-            readingPos += CharEncoding.getCharSize(character);
-            while (FormatSpec.INVALID_CHARACTER != character
-                    && index < FormatSpec.MAX_WORD_LENGTH) {
-                mCharacterBufferForReadingVer4PtNodeInfo[index++] = character;
-                character = CharEncoding.readChar(mDictBuffer);
-                readingPos += CharEncoding.getCharSize(character);
-            }
-            characters = Arrays.copyOfRange(mCharacterBufferForReadingVer4PtNodeInfo, 0, index);
-        } else {
-            final int character = CharEncoding.readChar(mDictBuffer);
-            readingPos += CharEncoding.getCharSize(character);
-            characters = new int[] { character };
-        }
-        final int terminalId;
-        if (0 != (FormatSpec.FLAG_IS_TERMINAL & flags)) {
-            terminalId = PtNodeReader.readTerminalId(mDictBuffer);
-            readingPos += FormatSpec.PTNODE_TERMINAL_ID_SIZE;
-        } else {
-            terminalId = PtNode.NOT_A_TERMINAL;
-        }
-
-        int childrenPos = PtNodeReader.readChildrenAddress(mDictBuffer, flags, options);
-        if (childrenPos != FormatSpec.NO_CHILDREN_ADDRESS) {
-            childrenPos += readingPos;
-        }
-        readingPos += BinaryDictIOUtils.getChildrenAddressSize(flags, options);
-
-        return new Ver4PtNodeInfo(flags, characters, terminalId, childrenPos, parentPos,
-                readingPos - ptNodePos);
-    }
-
-    @Override
-    public PtNodeInfo readPtNode(final int ptNodePos, final FormatOptions options) {
-        final Ver4PtNodeInfo nodeInfo = readVer4PtNodeInfo(ptNodePos, options);
-
-        final int frequency;
-        if (0 != (FormatSpec.FLAG_IS_TERMINAL & nodeInfo.mFlags)) {
-            frequency = PtNodeReader.readFrequency(mFrequencyBuffer, nodeInfo.mTerminalId, options);
-        } else {
-            frequency = PtNode.NOT_A_TERMINAL;
-        }
-
-        final ArrayList<WeightedString> shortcutTargets = mShortcutReader.readShortcuts(
-                nodeInfo.mTerminalId);
-        final ArrayList<PendingAttribute> bigrams = mBigramReader.readTargetsAndFrequencies(
-                nodeInfo.mTerminalId, mTerminalAddressTableBuffer, options);
-
-        return new PtNodeInfo(ptNodePos, ptNodePos + nodeInfo.mNodeSize, nodeInfo.mFlags,
-                nodeInfo.mCharacters, frequency, nodeInfo.mParentPos, nodeInfo.mChildrenPos,
-                shortcutTargets, bigrams);
-    }
-
-    private void deleteDictFiles() {
-        final File[] files = mDictDirectory.listFiles();
-        for (int i = 0; i < files.length; ++i) {
-            files[i].delete();
-        }
+        return mBinaryDictionary.getHeader();
     }
 
     @Override
     public FusionDictionary readDictionaryBinary(final FusionDictionary dict,
             final boolean deleteDictIfBroken)
             throws FileNotFoundException, IOException, UnsupportedFormatException {
-        if (mDictBuffer == null) {
-            openDictBuffer();
-        }
-        try {
-            return BinaryDictDecoderUtils.readDictionaryBinary(this, dict);
-        } catch (IOException e) {
-            Log.e(TAG, "The dictionary " + mDictDirectory.getName() + " is broken.", e);
-            if (deleteDictIfBroken) {
-                deleteDictFiles();
+        final DictionaryHeader header = readHeader();
+        final FusionDictionary fusionDict = dict != null ? dict :
+                new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions);
+        int token = 0;
+        final ArrayList<WordProperty> wordProperties = CollectionUtils.newArrayList();
+        do {
+            final BinaryDictionary.GetNextWordPropertyResult result =
+                    mBinaryDictionary.getNextWordProperty(token);
+            final WordProperty wordProperty = result.mWordProperty;
+            if (wordProperty == null) {
+                if (deleteDictIfBroken) {
+                    mBinaryDictionary.close();
+                    FileUtils.deleteRecursively(mDictDirectory);
+                }
+                return null;
             }
-            throw e;
-        } catch (UnsupportedFormatException e) {
-            Log.e(TAG, "The dictionary " + mDictDirectory.getName() + " is broken.", e);
-            if (deleteDictIfBroken) {
-                deleteDictFiles();
-            }
-            throw e;
-        }
-    }
+            wordProperties.add(wordProperty);
+            token = result.mNextToken;
+        } while (token != 0);
 
-    @Override
-    public void setPosition(int newPos) {
-        mDictBuffer.position(newPos);
-    }
-
-    @Override
-    public int getPosition() {
-        return mDictBuffer.position();
-    }
-
-    @Override
-    public int readPtNodeCount() {
-        return BinaryDictDecoderUtils.readPtNodeCount(mDictBuffer);
-    }
-
-    @Override
-    public boolean readAndFollowForwardLink() {
-        final int forwardLinkPos = mDictBuffer.position();
-        int nextRelativePos = BinaryDictDecoderUtils.readSInt24(mDictBuffer);
-        if (nextRelativePos != FormatSpec.NO_FORWARD_LINK_ADDRESS) {
-            final int nextPos = forwardLinkPos + nextRelativePos;
-            if (nextPos >= 0 && nextPos < mDictBuffer.limit()) {
-              mDictBuffer.position(nextPos);
-              return true;
+        // Insert unigrams to the fusion dictionary.
+        for (final WordProperty wordProperty : wordProperties) {
+            // TODO: Support probability that is -1.
+            final int probability = wordProperty.getProbability() < 0 ?
+                    0 : wordProperty.getProbability();
+            if (wordProperty.mIsBlacklistEntry) {
+                fusionDict.addBlacklistEntry(wordProperty.mWord, wordProperty.mShortcutTargets,
+                        wordProperty.mIsNotAWord);
+            } else {
+                fusionDict.add(wordProperty.mWord, probability,
+                        wordProperty.mShortcutTargets, wordProperty.mIsNotAWord);
             }
         }
-        return false;
-    }
-
-    @Override
-    public boolean hasNextPtNodeArray() {
-        return mDictBuffer.position() != FormatSpec.NO_FORWARD_LINK_ADDRESS;
-    }
-
-    @Override
-    @UsedForTesting
-    public void skipPtNode(final FormatOptions formatOptions) {
-        final int flags = PtNodeReader.readPtNodeOptionFlags(mDictBuffer);
-        PtNodeReader.readParentAddress(mDictBuffer, formatOptions);
-        BinaryDictIOUtils.skipString(mDictBuffer,
-                (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS) != 0);
-        if ((flags & FormatSpec.FLAG_IS_TERMINAL) != 0) PtNodeReader.readTerminalId(mDictBuffer);
-        PtNodeReader.readChildrenAddress(mDictBuffer, flags, formatOptions);
+        // Insert bigrams to the fusion dictionary.
+        for (final WordProperty wordProperty : wordProperties) {
+            if (wordProperty.mBigrams == null) {
+                continue;
+            }
+            final String word0 = wordProperty.mWord;
+            for (final WeightedString bigram : wordProperty.mBigrams) {
+                fusionDict.setBigram(word0, bigram.mWord, bigram.getProbability());
+            }
+        }
+        return fusionDict;
     }
 }
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
index a5b0135..147844f 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
@@ -71,27 +71,29 @@
             // Somehow createEmptyDictFile returned true, but the file was not created correctly
             throw new IOException("Cannot create dictionary file");
         }
-        for (final Word word : dict) {
+        for (final WordProperty wordProperty : dict) {
             // TODO: switch to addMultipleDictionaryEntries when they support shortcuts
-            if (null == word.mShortcutTargets || word.mShortcutTargets.isEmpty()) {
-                binaryDict.addUnigramWord(word.mWord, word.mFrequency,
+            if (null == wordProperty.mShortcutTargets || wordProperty.mShortcutTargets.isEmpty()) {
+                binaryDict.addUnigramWord(wordProperty.mWord, wordProperty.getProbability(),
                         null /* shortcutTarget */, 0 /* shortcutProbability */,
-                        word.mIsNotAWord, word.mIsBlacklistEntry, 0 /* timestamp */);
+                        wordProperty.mIsNotAWord, wordProperty.mIsBlacklistEntry,
+                        0 /* timestamp */);
             } else {
-                for (final WeightedString shortcutTarget : word.mShortcutTargets) {
-                    binaryDict.addUnigramWord(word.mWord, word.mFrequency,
+                for (final WeightedString shortcutTarget : wordProperty.mShortcutTargets) {
+                    binaryDict.addUnigramWord(wordProperty.mWord, wordProperty.getProbability(),
                             shortcutTarget.mWord, shortcutTarget.getProbability(),
-                            word.mIsNotAWord, word.mIsBlacklistEntry, 0 /* timestamp */);
+                            wordProperty.mIsNotAWord, wordProperty.mIsBlacklistEntry,
+                            0 /* timestamp */);
                 }
             }
             if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) {
                 binaryDict.flushWithGC();
             }
         }
-        for (final Word word0 : dict) {
-            if (null == word0.mBigrams) continue;
-            for (final WeightedString word1 : word0.mBigrams) {
-                binaryDict.addBigramWords(word0.mWord, word1.mWord, word1.getProbability(),
+        for (final WordProperty word0Property : dict) {
+            if (null == word0Property.mBigrams) continue;
+            for (final WeightedString word1 : word0Property.mBigrams) {
+                binaryDict.addBigramWords(word0Property.mWord, word1.mWord, word1.getProbability(),
                         0 /* timestamp */);
                 if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) {
                     binaryDict.flushWithGC();
diff --git a/java/src/com/android/inputmethod/latin/makedict/Word.java b/java/src/com/android/inputmethod/latin/makedict/Word.java
deleted file mode 100644
index 0eabb7b..0000000
--- a/java/src/com/android/inputmethod/latin/makedict/Word.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.latin.makedict;
-
-import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-/**
- * Utility class for a word with a frequency.
- *
- * This is chiefly used to iterate a dictionary.
- */
-public final class Word implements Comparable<Word> {
-    public final String mWord;
-    public final int mFrequency;
-    public final ArrayList<WeightedString> mShortcutTargets;
-    public final ArrayList<WeightedString> mBigrams;
-    public final boolean mIsNotAWord;
-    public final boolean mIsBlacklistEntry;
-
-    private int mHashCode = 0;
-
-    public Word(final String word, final int frequency,
-            final ArrayList<WeightedString> shortcutTargets,
-            final ArrayList<WeightedString> bigrams,
-            final boolean isNotAWord, final boolean isBlacklistEntry) {
-        mWord = word;
-        mFrequency = frequency;
-        mShortcutTargets = shortcutTargets;
-        mBigrams = bigrams;
-        mIsNotAWord = isNotAWord;
-        mIsBlacklistEntry = isBlacklistEntry;
-    }
-
-    private static int computeHashCode(Word word) {
-        return Arrays.hashCode(new Object[] {
-                word.mWord,
-                word.mFrequency,
-                word.mShortcutTargets.hashCode(),
-                word.mBigrams.hashCode(),
-                word.mIsNotAWord,
-                word.mIsBlacklistEntry
-        });
-    }
-
-    /**
-     * Three-way comparison.
-     *
-     * A Word x is greater than a word y if x has a higher frequency. If they have the same
-     * frequency, they are sorted in lexicographic order.
-     */
-    @Override
-    public int compareTo(Word w) {
-        if (mFrequency < w.mFrequency) return 1;
-        if (mFrequency > w.mFrequency) return -1;
-        return mWord.compareTo(w.mWord);
-    }
-
-    /**
-     * Equality test.
-     *
-     * Words are equal if they have the same frequency, the same spellings, and the same
-     * attributes.
-     */
-    @Override
-    public boolean equals(Object o) {
-        if (o == this) return true;
-        if (!(o instanceof Word)) return false;
-        Word w = (Word)o;
-        return mFrequency == w.mFrequency && mWord.equals(w.mWord)
-                && mShortcutTargets.equals(w.mShortcutTargets)
-                && mBigrams.equals(w.mBigrams)
-                && mIsNotAWord == w.mIsNotAWord
-                && mIsBlacklistEntry == w.mIsBlacklistEntry;
-    }
-
-    @Override
-    public int hashCode() {
-        if (mHashCode == 0) {
-            mHashCode = computeHashCode(this);
-        }
-        return mHashCode;
-    }
-}
diff --git a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
new file mode 100644
index 0000000..b93a0a5
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.makedict;
+
+import com.android.inputmethod.annotations.UsedForTesting;
+import com.android.inputmethod.latin.BinaryDictionary;
+import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
+import com.android.inputmethod.latin.utils.CollectionUtils;
+import com.android.inputmethod.latin.utils.CombinedFormatUtils;
+import com.android.inputmethod.latin.utils.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * Utility class for a word with a probability.
+ *
+ * This is chiefly used to iterate a dictionary.
+ */
+public final class WordProperty implements Comparable<WordProperty> {
+    public final String mWord;
+    public final ProbabilityInfo mProbabilityInfo;
+    public final ArrayList<WeightedString> mShortcutTargets;
+    public final ArrayList<WeightedString> mBigrams;
+    public final boolean mIsNotAWord;
+    public final boolean mIsBlacklistEntry;
+    public final boolean mHasShortcuts;
+    public final boolean mHasBigrams;
+
+    private int mHashCode = 0;
+
+    public WordProperty(final String word, final int probability,
+            final ArrayList<WeightedString> shortcutTargets,
+            final ArrayList<WeightedString> bigrams,
+            final boolean isNotAWord, final boolean isBlacklistEntry) {
+        mWord = word;
+        mProbabilityInfo = new ProbabilityInfo(probability);
+        mShortcutTargets = shortcutTargets;
+        mBigrams = bigrams;
+        mIsNotAWord = isNotAWord;
+        mIsBlacklistEntry = isBlacklistEntry;
+        mHasBigrams = bigrams != null && !bigrams.isEmpty();
+        mHasShortcuts = shortcutTargets != null && !shortcutTargets.isEmpty();
+    }
+
+    private static ProbabilityInfo createProbabilityInfoFromArray(final int[] probabilityInfo) {
+      return new ProbabilityInfo(
+              probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_PROBABILITY_INDEX],
+              probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_TIMESTAMP_INDEX],
+              probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_LEVEL_INDEX],
+              probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_COUNT_INDEX]);
+    }
+
+    // Construct word property using information from native code.
+    // This represents invalid word when the probability is BinaryDictionary.NOT_A_PROBABILITY.
+    public WordProperty(final int[] codePoints, final boolean isNotAWord,
+            final boolean isBlacklisted, final boolean hasBigram,
+            final boolean hasShortcuts, final int[] probabilityInfo,
+            final ArrayList<int[]> bigramTargets, final ArrayList<int[]> bigramProbabilityInfo,
+            final ArrayList<int[]> shortcutTargets,
+            final ArrayList<Integer> shortcutProbabilities) {
+        mWord = StringUtils.getStringFromNullTerminatedCodePointArray(codePoints);
+        mProbabilityInfo = createProbabilityInfoFromArray(probabilityInfo);
+        mShortcutTargets = CollectionUtils.newArrayList();
+        mBigrams = CollectionUtils.newArrayList();
+        mIsNotAWord = isNotAWord;
+        mIsBlacklistEntry = isBlacklisted;
+        mHasShortcuts = hasShortcuts;
+        mHasBigrams = hasBigram;
+
+        final int bigramTargetCount = bigramTargets.size();
+        for (int i = 0; i < bigramTargetCount; i++) {
+            final String bigramTargetString =
+                    StringUtils.getStringFromNullTerminatedCodePointArray(bigramTargets.get(i));
+            mBigrams.add(new WeightedString(bigramTargetString,
+                    createProbabilityInfoFromArray(bigramProbabilityInfo.get(i))));
+        }
+
+        final int shortcutTargetCount = shortcutTargets.size();
+        for (int i = 0; i < shortcutTargetCount; i++) {
+            final String shortcutTargetString =
+                    StringUtils.getStringFromNullTerminatedCodePointArray(shortcutTargets.get(i));
+            mShortcutTargets.add(
+                    new WeightedString(shortcutTargetString, shortcutProbabilities.get(i)));
+        }
+    }
+
+    public int getProbability() {
+        return mProbabilityInfo.mProbability;
+    }
+
+    private static int computeHashCode(WordProperty word) {
+        return Arrays.hashCode(new Object[] {
+                word.mWord,
+                word.mProbabilityInfo,
+                word.mShortcutTargets.hashCode(),
+                word.mBigrams.hashCode(),
+                word.mIsNotAWord,
+                word.mIsBlacklistEntry
+        });
+    }
+
+    /**
+     * Three-way comparison.
+     *
+     * A Word x is greater than a word y if x has a higher frequency. If they have the same
+     * frequency, they are sorted in lexicographic order.
+     */
+    @Override
+    public int compareTo(final WordProperty w) {
+        if (getProbability() < w.getProbability()) return 1;
+        if (getProbability() > w.getProbability()) return -1;
+        return mWord.compareTo(w.mWord);
+    }
+
+    /**
+     * Equality test.
+     *
+     * Words are equal if they have the same frequency, the same spellings, and the same
+     * attributes.
+     */
+    @Override
+    public boolean equals(Object o) {
+        if (o == this) return true;
+        if (!(o instanceof WordProperty)) return false;
+        WordProperty w = (WordProperty)o;
+        return mProbabilityInfo.equals(w.mProbabilityInfo) && mWord.equals(w.mWord)
+                && mShortcutTargets.equals(w.mShortcutTargets) && mBigrams.equals(w.mBigrams)
+                && mIsNotAWord == w.mIsNotAWord && mIsBlacklistEntry == w.mIsBlacklistEntry
+                && mHasBigrams == w.mHasBigrams && mHasShortcuts && w.mHasBigrams;
+    }
+
+    @Override
+    public int hashCode() {
+        if (mHashCode == 0) {
+            mHashCode = computeHashCode(this);
+        }
+        return mHashCode;
+    }
+
+    @UsedForTesting
+    public boolean isValid() {
+        return getProbability() != BinaryDictionary.NOT_A_PROBABILITY;
+    }
+
+    @Override
+    public String toString() {
+        return CombinedFormatUtils.formatWordProperty(this);
+    }
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
index fa5ae92..c87dd15 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
@@ -18,6 +18,7 @@
 
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.res.Resources;
 import android.os.Bundle;
 import android.os.Process;
 import android.preference.CheckBoxPreference;
@@ -32,6 +33,7 @@
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug;
 import com.android.inputmethod.latin.utils.ApplicationUtils;
+import com.android.inputmethod.latin.utils.ResourceUtils;
 
 public final class DebugSettings extends PreferenceFragment
         implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -42,6 +44,14 @@
     public static final String PREF_STATISTICS_LOGGING = "enable_logging";
     public static final String PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG =
             "use_only_personalization_dictionary_for_debug";
+    public static final String PREF_KEY_PREVIEW_SHOW_UP_START_SCALE =
+            "pref_key_preview_show_up_start_scale";
+    public static final String PREF_KEY_PREVIEW_DISMISS_END_SCALE =
+            "pref_key_preview_dismiss_end_scale";
+    public static final String PREF_KEY_PREVIEW_SHOW_UP_DURATION =
+            "pref_key_preview_show_up_duration";
+    public static final String PREF_KEY_PREVIEW_DISMISS_DURATION =
+            "pref_key_preview_dismiss_duration";
     private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary";
     private static final String PREF_DUMP_CONTACTS_DICT = "dump_contacts_dict";
     private static final String PREF_DUMP_USER_DICT = "dump_user_dict";
@@ -101,6 +111,17 @@
                 dictDumpPrefClickListener);
         findPreference(PREF_DUMP_PERSONALIZATION_DICT).setOnPreferenceClickListener(
                 dictDumpPrefClickListener);
+        final Resources res = getResources();
+        setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_DURATION,
+                res.getInteger(R.integer.config_key_preview_show_up_duration));
+        setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_DISMISS_DURATION,
+                res.getInteger(R.integer.config_key_preview_dismiss_duration));
+        setupKeyPreviewAnimationScale(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_START_SCALE,
+                ResourceUtils.getFloatFromFraction(
+                        res, R.fraction.config_key_preview_show_up_start_scale));
+        setupKeyPreviewAnimationScale(prefs, res, PREF_KEY_PREVIEW_DISMISS_END_SCALE,
+                ResourceUtils.getFloatFromFraction(
+                        res, R.fraction.config_key_preview_dismiss_end_scale));
 
         mServiceNeedsRestart = false;
         mDebugMode = (CheckBoxPreference) findPreference(PREF_DEBUG_MODE);
@@ -180,4 +201,92 @@
             mDebugMode.setSummary(version);
         }
     }
+
+    private void setupKeyPreviewAnimationScale(final SharedPreferences sp, final Resources res,
+            final String prefKey, final float defaultValue) {
+        final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
+        if (pref == null) {
+            return;
+        }
+        pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+            private static final float PERCENTAGE_FLOAT = 100.0f;
+
+            private float getValueFromPercentage(final int percentage) {
+                return percentage / PERCENTAGE_FLOAT;
+            }
+
+            private int getPercentageFromValue(final float floatValue) {
+                return (int)(floatValue * PERCENTAGE_FLOAT);
+            }
+
+            @Override
+            public void writeValue(final int value, final String key) {
+                sp.edit().putFloat(key, getValueFromPercentage(value)).apply();
+            }
+
+            @Override
+            public void writeDefaultValue(final String key) {
+                sp.edit().remove(key).apply();
+            }
+
+            @Override
+            public int readValue(final String key) {
+                return getPercentageFromValue(
+                        Settings.readKeyPreviewAnimationScale(sp, key, defaultValue));
+            }
+
+            @Override
+            public int readDefaultValue(final String key) {
+                return getPercentageFromValue(defaultValue);
+            }
+
+            @Override
+            public String getValueText(final int value) {
+                if (value < 0) {
+                    return res.getString(R.string.settings_system_default);
+                }
+                return String.format("%d%%", value);
+            }
+
+            @Override
+            public void feedbackValue(final int value) {}
+        });
+    }
+
+    private void setupKeyPreviewAnimationDuration(final SharedPreferences sp, final Resources res,
+            final String prefKey, final int defaultValue) {
+        final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
+        if (pref == null) {
+            return;
+        }
+        pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+            @Override
+            public void writeValue(final int value, final String key) {
+                sp.edit().putInt(key, value).apply();
+            }
+
+            @Override
+            public void writeDefaultValue(final String key) {
+                sp.edit().remove(key).apply();
+            }
+
+            @Override
+            public int readValue(final String key) {
+                return Settings.readKeyPreviewAnimationDuration(sp, key, defaultValue);
+            }
+
+            @Override
+            public int readDefaultValue(final String key) {
+                return defaultValue;
+            }
+
+            @Override
+            public String getValueText(final int value) {
+                return res.getString(R.string.abbreviation_unit_milliseconds, value);
+            }
+
+            @Override
+            public void feedbackValue(final int value) {}
+        });
+    }
 }
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 9bf269b..f0f7de7 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -107,6 +107,9 @@
     public static final String PREF_EMOJI_CATEGORY_LAST_TYPED_ID = "emoji_category_last_typed_id";
     public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_ID = "last_shown_emoji_category_id";
 
+    private static final float UNDEFINED_PREFERENCE_VALUE_FLOAT = -1.0f;
+    private static final int UNDEFINED_PREFERENCE_VALUE_INT = -1;
+
     private Context mContext;
     private Resources mRes;
     private SharedPreferences mPrefs;
@@ -301,8 +304,10 @@
 
     public static float readKeypressSoundVolume(final SharedPreferences prefs,
             final Resources res) {
-        final float volume = prefs.getFloat(PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
-        return (volume >= 0) ? volume : readDefaultKeypressSoundVolume(res);
+        final float volume = prefs.getFloat(
+                PREF_KEYPRESS_SOUND_VOLUME, UNDEFINED_PREFERENCE_VALUE_FLOAT);
+        return (volume != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? volume
+                : readDefaultKeypressSoundVolume(res);
     }
 
     public static float readDefaultKeypressSoundVolume(final Resources res) {
@@ -312,8 +317,10 @@
 
     public static int readKeyLongpressTimeout(final SharedPreferences prefs,
             final Resources res) {
-        final int ms = prefs.getInt(PREF_KEY_LONGPRESS_TIMEOUT, -1);
-        return (ms >= 0) ? ms : readDefaultKeyLongpressTimeout(res);
+        final int milliseconds = prefs.getInt(
+                PREF_KEY_LONGPRESS_TIMEOUT, UNDEFINED_PREFERENCE_VALUE_INT);
+        return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
+                : readDefaultKeyLongpressTimeout(res);
     }
 
     public static int readDefaultKeyLongpressTimeout(final Resources res) {
@@ -322,8 +329,10 @@
 
     public static int readKeypressVibrationDuration(final SharedPreferences prefs,
             final Resources res) {
-        final int ms = prefs.getInt(PREF_VIBRATION_DURATION_SETTINGS, -1);
-        return (ms >= 0) ? ms : readDefaultKeypressVibrationDuration(res);
+        final int milliseconds = prefs.getInt(
+                PREF_VIBRATION_DURATION_SETTINGS, UNDEFINED_PREFERENCE_VALUE_INT);
+        return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
+                : readDefaultKeypressVibrationDuration(res);
     }
 
     public static int readDefaultKeypressVibrationDuration(final Resources res) {
@@ -335,6 +344,18 @@
         return prefs.getBoolean(DebugSettings.PREF_USABILITY_STUDY_MODE, true);
     }
 
+    public static float readKeyPreviewAnimationScale(final SharedPreferences prefs,
+            final String prefKey, final float defaultValue) {
+        final float fraction = prefs.getFloat(prefKey, UNDEFINED_PREFERENCE_VALUE_FLOAT);
+        return (fraction != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? fraction : defaultValue;
+    }
+
+    public static int readKeyPreviewAnimationDuration(final SharedPreferences prefs,
+            final String prefKey, final int defaultValue) {
+        final int milliseconds = prefs.getInt(prefKey, UNDEFINED_PREFERENCE_VALUE_INT);
+        return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds : defaultValue;
+    }
+
     public static boolean readUseFullscreenMode(final Resources res) {
         return res.getBoolean(R.bool.config_use_fullscreen_mode);
     }
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 2979544..90d3519 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -29,6 +29,7 @@
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.RichInputMethodManager;
 import com.android.inputmethod.latin.utils.AsyncResultHolder;
+import com.android.inputmethod.latin.utils.ResourceUtils;
 import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
 
 import java.util.Arrays;
@@ -93,6 +94,10 @@
 
     // Debug settings
     public final boolean mIsInternal;
+    public final int mKeyPreviewShowUpDuration;
+    public final int mKeyPreviewDismissDuration;
+    public final float mKeyPreviewShowUpStartScale;
+    public final float mKeyPreviewDismissEndScale;
 
     public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
             final InputAttributes inputAttributes) {
@@ -149,6 +154,20 @@
         AdditionalFeaturesSettingUtils.readAdditionalFeaturesPreferencesIntoArray(
                 prefs, mAdditionalFeaturesSettingValues);
         mIsInternal = Settings.isInternal(prefs);
+        mKeyPreviewShowUpDuration = Settings.readKeyPreviewAnimationDuration(
+                prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION,
+                res.getInteger(R.integer.config_key_preview_show_up_duration));
+        mKeyPreviewDismissDuration = Settings.readKeyPreviewAnimationDuration(
+                prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION,
+                res.getInteger(R.integer.config_key_preview_dismiss_duration));
+        mKeyPreviewShowUpStartScale = Settings.readKeyPreviewAnimationScale(
+                prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_SCALE,
+                ResourceUtils.getFloatFromFraction(
+                        res, R.fraction.config_key_preview_show_up_start_scale));
+        mKeyPreviewDismissEndScale = Settings.readKeyPreviewAnimationScale(
+                prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_SCALE,
+                ResourceUtils.getFloatFromFraction(
+                        res, R.fraction.config_key_preview_dismiss_end_scale));
         mUseOnlyPersonalizationDictionaryForDebug = prefs.getBoolean(
                 DebugSettings.PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG, false);
         mDisplayOrientation = res.getConfiguration().orientation;
diff --git a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
index 70cb2b2..60ca5ba 100644
--- a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
+++ b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
@@ -75,7 +75,7 @@
         final ArrayList<SuggestedWordInfo> puncList = CollectionUtils.newArrayList();
         if (puncs != null) {
             for (final String puncSpec : puncs) {
-                // TODO: Stop using KeySpceParser.getLabel().
+                // TODO: Stop using KeySpecParser.getLabel().
                 // TODO: Punctuation suggestions should honor RTL languages.
                 puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec),
                         SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED,
@@ -84,7 +84,7 @@
                         SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
             }
         }
-        return new SuggestedWords(puncList,
+        return new SuggestedWords(puncList, null /* rawSuggestions */,
                 false /* typedWordValid */,
                 false /* hasAutoCorrectionCandidate */,
                 true /* isPunctuationSuggestions */,
diff --git a/java/src/com/android/inputmethod/latin/utils/CombinedFormatUtils.java b/java/src/com/android/inputmethod/latin/utils/CombinedFormatUtils.java
new file mode 100644
index 0000000..bb7ae2f
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/utils/CombinedFormatUtils.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.latin.utils;
+
+import com.android.inputmethod.latin.makedict.DictionaryHeader;
+import com.android.inputmethod.latin.makedict.ProbabilityInfo;
+import com.android.inputmethod.latin.makedict.WordProperty;
+import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
+
+import java.util.HashMap;
+
+public class CombinedFormatUtils {
+    public static final String DICTIONARY_TAG = "dictionary";
+    public static final String BIGRAM_TAG = "bigram";
+    public static final String SHORTCUT_TAG = "shortcut";
+    public static final String PROBABILITY_TAG = "f";
+    public static final String HISTORICAL_INFO_TAG = "historicalInfo";
+    public static final String HISTORICAL_INFO_SEPARATOR = ":";
+    public static final String WORD_TAG = "word";
+    public static final String NOT_A_WORD_TAG = "not_a_word";
+    public static final String BLACKLISTED_TAG = "blacklisted";
+
+    public static String formatAttributeMap(final HashMap<String, String> attributeMap) {
+        final StringBuilder builder = new StringBuilder();
+        builder.append(DICTIONARY_TAG + "=");
+        if (attributeMap.containsKey(DictionaryHeader.DICTIONARY_ID_KEY)) {
+            builder.append(attributeMap.get(DictionaryHeader.DICTIONARY_ID_KEY));
+        }
+        for (final String key : attributeMap.keySet()) {
+            if (key.equals(DictionaryHeader.DICTIONARY_ID_KEY)) {
+                continue;
+            }
+            final String value = attributeMap.get(key);
+            builder.append("," + key + "=" + value);
+        }
+        builder.append("\n");
+        return builder.toString();
+    }
+
+    public static String formatWordProperty(final WordProperty wordProperty) {
+        final StringBuilder builder = new StringBuilder();
+        builder.append(" " + WORD_TAG + "=" + wordProperty.mWord);
+        builder.append(",");
+        builder.append(formatProbabilityInfo(wordProperty.mProbabilityInfo));
+        if (wordProperty.mIsNotAWord) {
+            builder.append("," + NOT_A_WORD_TAG + "=true");
+        }
+        if (wordProperty.mIsBlacklistEntry) {
+            builder.append("," + BLACKLISTED_TAG + "=true");
+        }
+        builder.append("\n");
+        if (wordProperty.mShortcutTargets != null) {
+            for (final WeightedString shortcutTarget : wordProperty.mShortcutTargets) {
+                builder.append("  " + SHORTCUT_TAG + "=" + shortcutTarget.mWord);
+                builder.append(",");
+                builder.append(formatProbabilityInfo(shortcutTarget.mProbabilityInfo));
+                builder.append("\n");
+            }
+        }
+        if (wordProperty.mBigrams != null) {
+            for (final WeightedString bigram : wordProperty.mBigrams) {
+                builder.append("  " + BIGRAM_TAG + "=" + bigram.mWord);
+                builder.append(",");
+                builder.append(formatProbabilityInfo(bigram.mProbabilityInfo));
+                builder.append("\n");
+            }
+        }
+        return builder.toString();
+    }
+
+    public static String formatProbabilityInfo(final ProbabilityInfo probabilityInfo) {
+        final StringBuilder builder = new StringBuilder();
+        builder.append(PROBABILITY_TAG + "=" + probabilityInfo.mProbability);
+        if (probabilityInfo.hasHistoricalInfo()) {
+            builder.append(",");
+            builder.append(HISTORICAL_INFO_TAG + "=");
+            builder.append(probabilityInfo.mTimestamp);
+            builder.append(HISTORICAL_INFO_SEPARATOR);
+            builder.append(probabilityInfo.mLevel);
+            builder.append(HISTORICAL_INFO_SEPARATOR);
+            builder.append(probabilityInfo.mCount);
+        }
+        return builder.toString();
+    }
+}
diff --git a/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java b/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java
index deb28a0..3a1c24c 100644
--- a/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java
@@ -260,6 +260,10 @@
         return dimension >= 0;
     }
 
+    public static float getFloatFromFraction(final Resources res, final int fractionResId) {
+        return res.getFraction(fractionResId, 1, 1);
+    }
+
     public static float getFraction(final TypedArray a, final int index, final float defValue) {
         final TypedValue value = a.peekValue(index);
         if (value == null || !isFractionValue(value)) {
diff --git a/java/src/com/android/inputmethod/latin/utils/WordProperty.java b/java/src/com/android/inputmethod/latin/utils/WordProperty.java
deleted file mode 100644
index 37d1102..0000000
--- a/java/src/com/android/inputmethod/latin/utils/WordProperty.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package com.android.inputmethod.latin.utils;
-
-import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.BinaryDictionary;
-import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.ProbabilityInfo;
-
-import java.util.ArrayList;
-
-// This has information that belong to a unigram. This class has some detailed attributes such as
-// historical information but they have to be checked only for testing purpose.
-@UsedForTesting
-public class WordProperty {
-    public final String mCodePoints;
-    public final boolean mIsNotAWord;
-    public final boolean mIsBlacklisted;
-    public final boolean mHasBigrams;
-    public final boolean mHasShortcuts;
-    public final ProbabilityInfo mProbabilityInfo;
-    public final ArrayList<WeightedString> mBigramTargets = CollectionUtils.newArrayList();
-    public final ArrayList<ProbabilityInfo> mBigramProbabilityInfo = CollectionUtils.newArrayList();
-    public final ArrayList<WeightedString> mShortcutTargets = CollectionUtils.newArrayList();
-
-    private static ProbabilityInfo createProbabilityInfoFromArray(final int[] probabilityInfo) {
-        return new ProbabilityInfo(
-                probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_PROBABILITY_INDEX],
-                probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_TIMESTAMP_INDEX],
-                probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_LEVEL_INDEX],
-                probabilityInfo[BinaryDictionary.FORMAT_WORD_PROPERTY_COUNT_INDEX]);
-    }
-
-    // This represents invalid word when the probability is BinaryDictionary.NOT_A_PROBABILITY.
-    public WordProperty(final int[] codePoints, final boolean isNotAWord,
-            final boolean isBlacklisted, final boolean hasBigram,
-            final boolean hasShortcuts, final int[] probabilityInfo,
-            final ArrayList<int[]> bigramTargets, final ArrayList<int[]> bigramProbabilityInfo,
-            final ArrayList<int[]> shortcutTargets,
-            final ArrayList<Integer> shortcutProbabilities) {
-        mCodePoints = StringUtils.getStringFromNullTerminatedCodePointArray(codePoints);
-        mIsNotAWord = isNotAWord;
-        mIsBlacklisted = isBlacklisted;
-        mHasBigrams = hasBigram;
-        mHasShortcuts = hasShortcuts;
-        mProbabilityInfo = createProbabilityInfoFromArray(probabilityInfo);
-
-        final int bigramTargetCount = bigramTargets.size();
-        for (int i = 0; i < bigramTargetCount; i++) {
-            final String bigramTargetString =
-                    StringUtils.getStringFromNullTerminatedCodePointArray(bigramTargets.get(i));
-            final ProbabilityInfo bigramProbability =
-                    createProbabilityInfoFromArray(bigramProbabilityInfo.get(i));
-            mBigramTargets.add(
-                    new WeightedString(bigramTargetString, bigramProbability.mProbability));
-            mBigramProbabilityInfo.add(bigramProbability);
-        }
-
-        final int shortcutTargetCount = shortcutTargets.size();
-        for (int i = 0; i < shortcutTargetCount; i++) {
-            final String shortcutTargetString =
-                    StringUtils.getStringFromNullTerminatedCodePointArray(shortcutTargets.get(i));
-            mShortcutTargets.add(
-                    new WeightedString(shortcutTargetString, shortcutProbabilities.get(i)));
-        }
-    }
-
-    @UsedForTesting
-    public boolean isValid() {
-        return mProbabilityInfo.mProbability != BinaryDictionary.NOT_A_PROBABILITY;
-    }
-
-    @Override
-    public String toString() {
-        // TODO: Move this logic to CombinedInputOutput.
-        final StringBuffer builder = new StringBuffer();
-        builder.append(" word=" + mCodePoints);
-        builder.append(",");
-        builder.append("f=" + mProbabilityInfo.mProbability);
-        if (mIsNotAWord) {
-            builder.append(",");
-            builder.append("not_a_word=true");
-        }
-        if (mIsBlacklisted) {
-            builder.append(",");
-            builder.append("blacklisted=true");
-        }
-        if (mProbabilityInfo.mTimestamp != BinaryDictionary.NOT_A_VALID_TIMESTAMP) {
-            builder.append(",");
-            builder.append("historicalInfo=" + mProbabilityInfo);
-        }
-        builder.append("\n");
-        for (int i = 0; i < mBigramTargets.size(); i++) {
-            builder.append("  bigram=" + mBigramTargets.get(i).mWord);
-            builder.append(",");
-            builder.append("f=" + mBigramTargets.get(i).getProbability());
-            if (mBigramProbabilityInfo.get(i).mTimestamp
-                    != BinaryDictionary.NOT_A_VALID_TIMESTAMP) {
-                builder.append(",");
-                builder.append("historicalInfo=" + mBigramProbabilityInfo.get(i));
-            }
-            builder.append("\n");
-        }
-        for (int i = 0; i < mShortcutTargets.size(); i++) {
-            builder.append("  shortcut=" + mShortcutTargets.get(i).mWord);
-            builder.append(",");
-            builder.append("f=" + mShortcutTargets.get(i).getProbability());
-            builder.append("\n");
-        }
-        return builder.toString();
-    }
-}
\ No newline at end of file
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index f5c3ee6..cfdbb5b 100644
--- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -53,7 +53,7 @@
         return false;
     }
 
-    HeaderReadWriteUtils::AttributeMap attributeMap;
+    DictionaryHeaderStructurePolicy::AttributeMap attributeMap;
     for (int i = 0; i < keyCount; i++) {
         jstring keyString = static_cast<jstring>(
                 env->GetObjectArrayElement(attributeKeyStringArray, i));
@@ -61,7 +61,7 @@
         char keyChars[keyUtf8Length + 1];
         env->GetStringUTFRegion(keyString, 0, env->GetStringLength(keyString), keyChars);
         keyChars[keyUtf8Length] = '\0';
-        HeaderReadWriteUtils::AttributeMap::key_type key;
+        DictionaryHeaderStructurePolicy::AttributeMap::key_type key;
         HeaderReadWriteUtils::insertCharactersIntoVector(keyChars, &key);
 
         jstring valueString = static_cast<jstring>(
@@ -70,7 +70,7 @@
         char valueChars[valueUtf8Length + 1];
         env->GetStringUTFRegion(valueString, 0, env->GetStringLength(valueString), valueChars);
         valueChars[valueUtf8Length] = '\0';
-        HeaderReadWriteUtils::AttributeMap::mapped_type value;
+        DictionaryHeaderStructurePolicy::AttributeMap::mapped_type value;
         HeaderReadWriteUtils::insertCharactersIntoVector(valueChars, &value);
         attributeMap[key] = value;
     }
@@ -145,16 +145,42 @@
         jobject outAttributeValues) {
     Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
     if (!dictionary) return;
-    const int formatVersion = dictionary->getFormatVersionNumber();
+    const DictionaryHeaderStructurePolicy *const headerPolicy =
+            dictionary->getDictionaryStructurePolicy()->getHeaderStructurePolicy();
+    const int headerSize = headerPolicy->getSize();
+    env->SetIntArrayRegion(outHeaderSize, 0 /* start */, 1 /* len */, &headerSize);
+    const int formatVersion = headerPolicy->getFormatVersionNumber();
     env->SetIntArrayRegion(outFormatVersion, 0 /* start */, 1 /* len */, &formatVersion);
-    // TODO: Implement
+    // Output attribute map
+    jclass arrayListClass = env->FindClass("java/util/ArrayList");
+    jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z");
+    const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap =
+            headerPolicy->getAttributeMap();
+    for (DictionaryHeaderStructurePolicy::AttributeMap::const_iterator it = attributeMap->begin();
+            it != attributeMap->end(); ++it) {
+        // Output key
+        jintArray keyCodePointArray = env->NewIntArray(it->first.size());
+        env->SetIntArrayRegion(
+                keyCodePointArray, 0 /* start */, it->first.size(), &it->first.at(0));
+        env->CallVoidMethod(outAttributeKeys, addMethodId, keyCodePointArray);
+        env->DeleteLocalRef(keyCodePointArray);
+        // Output value
+        jintArray valueCodePointArray = env->NewIntArray(it->second.size());
+        env->SetIntArrayRegion(
+                valueCodePointArray, 0 /* start */, it->second.size(), &it->second.at(0));
+        env->CallVoidMethod(outAttributeValues, addMethodId, valueCodePointArray);
+        env->DeleteLocalRef(valueCodePointArray);
+    }
+    env->DeleteLocalRef(arrayListClass);
     return;
 }
 
 static int latinime_BinaryDictionary_getFormatVersion(JNIEnv *env, jclass clazz, jlong dict) {
     Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
     if (!dictionary) return 0;
-    return dictionary->getFormatVersionNumber();
+    const DictionaryHeaderStructurePolicy *const headerPolicy =
+            dictionary->getDictionaryStructurePolicy()->getHeaderStructurePolicy();
+    return headerPolicy->getFormatVersionNumber();
 }
 
 static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, jlong dict,
diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h
index 0a413cb..7f311f3 100644
--- a/native/jni/src/suggest/core/dictionary/dictionary.h
+++ b/native/jni/src/suggest/core/dictionary/dictionary.h
@@ -105,11 +105,6 @@
         return mDictionaryStructureWithBufferPolicy.get();
     }
 
-    int getFormatVersionNumber() const {
-        return mDictionaryStructureWithBufferPolicy.get()->getHeaderStructurePolicy()
-                ->getFormatVersionNumber();
-    }
-
  private:
     DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary);
 
diff --git a/native/jni/src/suggest/core/policy/dictionary_header_structure_policy.h b/native/jni/src/suggest/core/policy/dictionary_header_structure_policy.h
index 417620e..59748c8 100644
--- a/native/jni/src/suggest/core/policy/dictionary_header_structure_policy.h
+++ b/native/jni/src/suggest/core/policy/dictionary_header_structure_policy.h
@@ -17,6 +17,9 @@
 #ifndef LATINIME_DICTIONARY_HEADER_STRUCTURE_POLICY_H
 #define LATINIME_DICTIONARY_HEADER_STRUCTURE_POLICY_H
 
+#include <map>
+#include <vector>
+
 #include "defines.h"
 
 namespace latinime {
@@ -27,10 +30,16 @@
  */
 class DictionaryHeaderStructurePolicy {
  public:
+    typedef std::map<std::vector<int>, std::vector<int> > AttributeMap;
+
     virtual ~DictionaryHeaderStructurePolicy() {}
 
     virtual int getFormatVersionNumber() const = 0;
 
+    virtual int getSize() const = 0;
+
+    virtual const AttributeMap *getAttributeMap() const = 0;
+
     virtual bool requiresGermanUmlautProcessing() const = 0;
 
     virtual float getMultiWordCostMultiplier() const = 0;
diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp
index b5b5ed7..3ce57d9 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp
@@ -46,7 +46,8 @@
     }
     std::vector<int> keyCodePointVector;
     HeaderReadWriteUtils::insertCharactersIntoVector(key, &keyCodePointVector);
-    HeaderReadWriteUtils::AttributeMap::const_iterator it = mAttributeMap.find(keyCodePointVector);
+    DictionaryHeaderStructurePolicy::AttributeMap::const_iterator it =
+            mAttributeMap.find(keyCodePointVector);
     if (it == mAttributeMap.end()) {
         // The key was not found.
         outValue[0] = '?';
@@ -82,7 +83,7 @@
         const int unigramCount, const int bigramCount,
         const int extendedRegionSize, BufferWithExtendableBuffer *const outBuffer) const {
     int writingPos = 0;
-    HeaderReadWriteUtils::AttributeMap attributeMapToWrite(mAttributeMap);
+    DictionaryHeaderStructurePolicy::AttributeMap attributeMapToWrite(mAttributeMap);
     fillInHeader(updatesLastDecayedTime, unigramCount, bigramCount,
             extendedRegionSize, &attributeMapToWrite);
     if (!HeaderReadWriteUtils::writeDictionaryVersion(outBuffer, mDictFormatVersion,
@@ -113,7 +114,7 @@
 
 void HeaderPolicy::fillInHeader(const bool updatesLastDecayedTime, const int unigramCount,
         const int bigramCount, const int extendedRegionSize,
-        HeaderReadWriteUtils::AttributeMap *outAttributeMap) const {
+        DictionaryHeaderStructurePolicy::AttributeMap *outAttributeMap) const {
     HeaderReadWriteUtils::setIntAttribute(outAttributeMap, UNIGRAM_COUNT_KEY, unigramCount);
     HeaderReadWriteUtils::setIntAttribute(outAttributeMap, BIGRAM_COUNT_KEY, bigramCount);
     HeaderReadWriteUtils::setIntAttribute(outAttributeMap, EXTENDED_REGION_SIZE_KEY,
@@ -129,9 +130,9 @@
     }
 }
 
-/* static */ HeaderReadWriteUtils::AttributeMap
+/* static */ DictionaryHeaderStructurePolicy::AttributeMap
         HeaderPolicy::createAttributeMapAndReadAllAttributes(const uint8_t *const dictBuf) {
-    HeaderReadWriteUtils::AttributeMap attributeMap;
+    DictionaryHeaderStructurePolicy::AttributeMap attributeMap;
     HeaderReadWriteUtils::fetchAllHeaderAttributes(dictBuf, &attributeMap);
     return attributeMap;
 }
diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h
index a05e00c..fc34761 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h
@@ -57,7 +57,7 @@
     // Constructs header information using an attribute map.
     HeaderPolicy(const FormatUtils::FORMAT_VERSION dictFormatVersion,
             const std::vector<int> locale,
-            const HeaderReadWriteUtils::AttributeMap *const attributeMap)
+            const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap)
             : mDictFormatVersion(dictFormatVersion),
               mDictionaryFlags(HeaderReadWriteUtils::createAndGetDictionaryFlagsUsingAttributeMap(
                       attributeMap)), mSize(0), mAttributeMap(*attributeMap), mLocale(locale),
@@ -155,6 +155,10 @@
         return !isDecayingDict();
     }
 
+    const DictionaryHeaderStructurePolicy::AttributeMap *getAttributeMap() const {
+        return &mAttributeMap;
+    }
+
     void readHeaderValueOrQuestionMark(const char *const key,
             int *outValue, int outValueSize) const;
 
@@ -164,7 +168,7 @@
 
     void fillInHeader(const bool updatesLastDecayedTime,
             const int unigramCount, const int bigramCount, const int extendedRegionSize,
-            HeaderReadWriteUtils::AttributeMap *outAttributeMap) const;
+            DictionaryHeaderStructurePolicy::AttributeMap *outAttributeMap) const;
 
  private:
     DISALLOW_COPY_AND_ASSIGN(HeaderPolicy);
@@ -185,7 +189,7 @@
     const FormatUtils::FORMAT_VERSION mDictFormatVersion;
     const HeaderReadWriteUtils::DictionaryFlags mDictionaryFlags;
     const int mSize;
-    HeaderReadWriteUtils::AttributeMap mAttributeMap;
+    DictionaryHeaderStructurePolicy::AttributeMap mAttributeMap;
     const std::vector<int> mLocale;
     const float mMultiWordCostMultiplier;
     const bool mRequiresGermanUmlautProcessing;
@@ -201,7 +205,7 @@
     float readMultipleWordCostMultiplier() const;
     bool readRequiresGermanUmlautProcessing() const;
 
-    static HeaderReadWriteUtils::AttributeMap createAttributeMapAndReadAllAttributes(
+    static DictionaryHeaderStructurePolicy::AttributeMap createAttributeMapAndReadAllAttributes(
             const uint8_t *const dictBuf);
 };
 } // namespace latinime
diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp
index 850b0d8..d20accf 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp
@@ -36,6 +36,8 @@
 
 const HeaderReadWriteUtils::DictionaryFlags HeaderReadWriteUtils::NO_FLAGS = 0;
 
+typedef DictionaryHeaderStructurePolicy::AttributeMap AttributeMap;
+
 /* static */ int HeaderReadWriteUtils::getHeaderSize(const uint8_t *const dictBuf) {
     // See the format of the header in the comment in
     // BinaryDictionaryFormatUtils::detectFormatVersion()
@@ -51,7 +53,7 @@
 
 /* static */ HeaderReadWriteUtils::DictionaryFlags
         HeaderReadWriteUtils::createAndGetDictionaryFlagsUsingAttributeMap(
-                const HeaderReadWriteUtils::AttributeMap *const attributeMap) {
+                const AttributeMap *const attributeMap) {
     return NO_FLAGS;
 }
 
diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h
index 3433c04..4185a2e 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h
@@ -17,11 +17,10 @@
 #ifndef LATINIME_HEADER_READ_WRITE_UTILS_H
 #define LATINIME_HEADER_READ_WRITE_UTILS_H
 
-#include <map>
 #include <stdint.h>
-#include <vector>
 
 #include "defines.h"
+#include "suggest/core/policy/dictionary_header_structure_policy.h"
 #include "suggest/policyimpl/dictionary/utils/format_utils.h"
 
 namespace latinime {
@@ -31,7 +30,6 @@
 class HeaderReadWriteUtils {
  public:
     typedef uint16_t DictionaryFlags;
-    typedef std::map<std::vector<int>, std::vector<int> > AttributeMap;
 
     static int getHeaderSize(const uint8_t *const dictBuf);
 
@@ -43,10 +41,10 @@
     }
 
     static DictionaryFlags createAndGetDictionaryFlagsUsingAttributeMap(
-            const HeaderReadWriteUtils::AttributeMap *const attributeMap);
+            const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap);
 
     static void fetchAllHeaderAttributes(const uint8_t *const dictBuf,
-            AttributeMap *const headerAttributes);
+            DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes);
 
     static bool writeDictionaryVersion(BufferWithExtendableBuffer *const buffer,
             const FormatUtils::FORMAT_VERSION version, int *const writingPos);
@@ -58,31 +56,38 @@
             const int size, int *const writingPos);
 
     static bool writeHeaderAttributes(BufferWithExtendableBuffer *const buffer,
-            const AttributeMap *const headerAttributes, int *const writingPos);
+            const DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
+            int *const writingPos);
 
     /**
      * Methods for header attributes.
      */
-    static void setCodePointVectorAttribute(AttributeMap *const headerAttributes,
+    static void setCodePointVectorAttribute(
+            DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
             const char *const key, const std::vector<int> value);
 
-    static void setBoolAttribute(AttributeMap *const headerAttributes,
+    static void setBoolAttribute(
+            DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
             const char *const key, const bool value);
 
-    static void setIntAttribute(AttributeMap *const headerAttributes,
+    static void setIntAttribute(
+            DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
             const char *const key, const int value);
 
     static const std::vector<int> readCodePointVectorAttributeValue(
-            const AttributeMap *const headerAttributes, const char *const key);
+            const DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
+            const char *const key);
 
-    static bool readBoolAttributeValue(const AttributeMap *const headerAttributes,
+    static bool readBoolAttributeValue(
+            const DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
             const char *const key, const bool defaultValue);
 
-    static int readIntAttributeValue(const AttributeMap *const headerAttributes,
+    static int readIntAttributeValue(
+            const DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
             const char *const key, const int defaultValue);
 
     static void insertCharactersIntoVector(const char *const characters,
-            AttributeMap::key_type *const key);
+            DictionaryHeaderStructurePolicy::AttributeMap::key_type *const key);
 
  private:
     DISALLOW_IMPLICIT_CONSTRUCTORS(HeaderReadWriteUtils);
@@ -98,11 +103,15 @@
     // Value for the "flags" field. It's unused at the moment.
     static const DictionaryFlags NO_FLAGS;
 
-    static void setIntAttributeInner(AttributeMap *const headerAttributes,
-            const AttributeMap::key_type *const key, const int value);
+    static void setIntAttributeInner(
+            DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
+            const DictionaryHeaderStructurePolicy::AttributeMap::key_type *const key,
+            const int value);
 
-    static int readIntAttributeValueInner(const AttributeMap *const headerAttributes,
-            const AttributeMap::key_type *const key, const int defaultValue);
+    static int readIntAttributeValueInner(
+            const DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
+            const DictionaryHeaderStructurePolicy::AttributeMap::key_type *const key,
+            const int defaultValue);
 };
 }
 #endif /* LATINIME_HEADER_READ_WRITE_UTILS_H */
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp
index 335ea0d..faef720 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.cpp
@@ -32,7 +32,7 @@
 
 /* static */ bool DictFileWritingUtils::createEmptyDictFile(const char *const filePath,
         const int dictVersion, const std::vector<int> localeAsCodePointVector,
-        const HeaderReadWriteUtils::AttributeMap *const attributeMap) {
+        const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap) {
     TimeKeeper::setCurrentTime();
     switch (dictVersion) {
         case FormatUtils::VERSION_4:
@@ -46,7 +46,7 @@
 
 /* static */ bool DictFileWritingUtils::createEmptyV4DictFile(const char *const dirPath,
         const std::vector<int> localeAsCodePointVector,
-        const HeaderReadWriteUtils::AttributeMap *const attributeMap) {
+        const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap) {
     HeaderPolicy headerPolicy(FormatUtils::VERSION_4, localeAsCodePointVector, attributeMap);
     Ver4DictBuffers::Ver4DictBuffersPtr dictBuffers =
             Ver4DictBuffers::createVer4DictBuffers(&headerPolicy);
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.h b/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.h
index c2ecff4..54ec651 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/utils/dict_file_writing_utils.h
@@ -32,7 +32,7 @@
 
     static bool createEmptyDictFile(const char *const filePath, const int dictVersion,
             const std::vector<int> localeAsCodePointVector,
-            const HeaderReadWriteUtils::AttributeMap *const attributeMap);
+            const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap);
 
     static bool flushAllHeaderAndBodyToFile(const char *const filePath,
             BufferWithExtendableBuffer *const dictHeader,
@@ -46,7 +46,7 @@
 
     static bool createEmptyV4DictFile(const char *const filePath,
             const std::vector<int> localeAsCodePointVector,
-            const HeaderReadWriteUtils::AttributeMap *const attributeMap);
+            const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap);
 
     static bool flushBufferToFile(const char *const filePath,
             const BufferWithExtendableBuffer *const buffer);
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java
index 5d84295..edeb6a6 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java
@@ -52,9 +52,8 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        final String language = TEST_LOCALE.getLanguage();
-        mCodesSet.setLanguage(language);
-        mTextsSet.setLanguage(language);
+        mCodesSet.setLocale(TEST_LOCALE);
+        mTextsSet.setLocale(TEST_LOCALE);
         final Context context = getContext();
         new RunInLocale<Void>() {
             @Override
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
index 5f301a8..42a94f4 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
@@ -41,7 +41,7 @@
 
         final Instrumentation instrumentation = getInstrumentation();
         final Context targetContext = instrumentation.getTargetContext();
-        mTextsSet.setLanguage(TEST_LOCALE.getLanguage());
+        mTextsSet.setLocale(TEST_LOCALE);
         new RunInLocale<Void>() {
             @Override
             protected Void job(final Resources res) {
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
index b1bdef8..1370041 100644
--- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
@@ -24,9 +24,9 @@
 import com.android.inputmethod.latin.makedict.CodePointUtils;
 import com.android.inputmethod.latin.makedict.FormatSpec;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
+import com.android.inputmethod.latin.makedict.WordProperty;
 import com.android.inputmethod.latin.utils.FileUtils;
 import com.android.inputmethod.latin.utils.LanguageModelParam;
-import com.android.inputmethod.latin.utils.WordProperty;
 
 import java.io.File;
 import java.io.IOException;
@@ -916,15 +916,15 @@
             }
             words.add(word);
             wordProbabilities.put(word, unigramProbability);
-            final WordProperty unigramProperty = binaryDictionary.getWordProperty(word);
-            assertEquals(word, unigramProperty.mCodePoints);
-            assertTrue(unigramProperty.isValid());
-            assertEquals(isNotAWord, unigramProperty.mIsNotAWord);
-            assertEquals(isBlacklisted, unigramProperty.mIsBlacklisted);
-            assertEquals(false, unigramProperty.mHasBigrams);
-            assertEquals(false, unigramProperty.mHasShortcuts);
-            assertEquals(unigramProbability, unigramProperty.mProbabilityInfo.mProbability);
-            assertTrue(unigramProperty.mShortcutTargets.isEmpty());
+            final WordProperty wordProperty = binaryDictionary.getWordProperty(word);
+            assertEquals(word, wordProperty.mWord);
+            assertTrue(wordProperty.isValid());
+            assertEquals(isNotAWord, wordProperty.mIsNotAWord);
+            assertEquals(isBlacklisted, wordProperty.mIsBlacklistEntry);
+            assertEquals(false, wordProperty.mHasBigrams);
+            assertEquals(false, wordProperty.mHasShortcuts);
+            assertEquals(unigramProbability, wordProperty.mProbabilityInfo.mProbability);
+            assertTrue(wordProperty.mShortcutTargets.isEmpty());
         }
 
         for (int i = 0; i < BIGRAM_COUNT; i++) {
@@ -955,18 +955,15 @@
                 continue;
             }
             final HashSet<String> bigramWord1s = bigrams.get(word0);
-            final WordProperty unigramProperty = binaryDictionary.getWordProperty(word0);
-            assertEquals(bigramWord1s.size(), unigramProperty.mBigramTargets.size());
-            assertEquals(unigramProperty.mBigramTargets.size(),
-                    unigramProperty.mBigramProbabilityInfo.size());
-            for (int j = 0; j < unigramProperty.mBigramTargets.size(); j++) {
-                final String word1 = unigramProperty.mBigramTargets.get(j).mWord;
+            final WordProperty wordProperty = binaryDictionary.getWordProperty(word0);
+            assertEquals(bigramWord1s.size(), wordProperty.mBigrams.size());
+            for (int j = 0; j < wordProperty.mBigrams.size(); j++) {
+                final String word1 = wordProperty.mBigrams.get(j).mWord;
                 assertTrue(bigramWord1s.contains(word1));
-                final int probability = unigramProperty.mBigramTargets.get(j).getProbability();
+                final int probability = wordProperty.mBigrams.get(j).getProbability();
                 assertEquals((int)bigramProbabilities.get(new Pair<String, String>(word0, word1)),
                         probability);
-                assertEquals(unigramProperty.mBigramProbabilityInfo.get(j).mProbability,
-                        probability);
+                assertEquals(wordProperty.mBigrams.get(j).getProbability(), probability);
             }
         }
     }
@@ -1045,15 +1042,15 @@
             final BinaryDictionary.GetNextWordPropertyResult result =
                     binaryDictionary.getNextWordProperty(token);
             final WordProperty wordProperty = result.mWordProperty;
-            final String word0 = wordProperty.mCodePoints;
+            final String word0 = wordProperty.mWord;
             assertEquals((int)wordProbabilitiesToCheckLater.get(word0),
                     wordProperty.mProbabilityInfo.mProbability);
             wordSet.remove(word0);
             final HashSet<String> bigramWord1s = bigrams.get(word0);
-            for (int j = 0; j < wordProperty.mBigramTargets.size(); j++) {
-                final String word1 = wordProperty.mBigramTargets.get(j).mWord;
+            for (int j = 0; j < wordProperty.mBigrams.size(); j++) {
+                final String word1 = wordProperty.mBigrams.get(j).mWord;
                 assertTrue(bigramWord1s.contains(word1));
-                final int probability = wordProperty.mBigramTargets.get(j).getProbability();
+                final int probability = wordProperty.mBigrams.get(j).getProbability();
                 final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
                 assertEquals((int)bigramProbabilitiesToCheckLater.get(bigram), probability);
                 bigramSet.remove(bigram);
diff --git a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
index 3753520..53839b6 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
@@ -46,7 +46,7 @@
         }
 
         final SuggestedWords words = new SuggestedWords(
-                list,
+                list, null /* rawSuggestions */,
                 false /* typedWordValid */,
                 false /* willAutoCorrect */,
                 false /* isPunctuationSuggestions */,
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
index 0815819..bc4452f 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
@@ -468,10 +468,6 @@
 
         runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER,
                 BinaryDictUtils.VERSION2_OPTIONS);
-        runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER,
-                BinaryDictUtils.VERSION4_OPTIONS_WITHOUT_TIMESTAMP);
-        runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER,
-                BinaryDictUtils.VERSION4_OPTIONS_WITH_TIMESTAMP);
 
         for (final String result : results) {
             Log.d(TAG, result);
@@ -483,10 +479,6 @@
 
         runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY,
                 BinaryDictUtils.VERSION2_OPTIONS);
-        runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY,
-                BinaryDictUtils.VERSION4_OPTIONS_WITHOUT_TIMESTAMP);
-        runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY,
-                BinaryDictUtils.VERSION4_OPTIONS_WITH_TIMESTAMP);
 
         for (final String result : results) {
             Log.d(TAG, result);
@@ -597,17 +589,8 @@
 
         runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY,
                 BinaryDictUtils.VERSION2_OPTIONS);
-        runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY,
-                BinaryDictUtils.VERSION4_OPTIONS_WITHOUT_TIMESTAMP);
-        runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY,
-                BinaryDictUtils.VERSION4_OPTIONS_WITH_TIMESTAMP);
-
         runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_BUFFER,
                 BinaryDictUtils.VERSION2_OPTIONS);
-        runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_BUFFER,
-                BinaryDictUtils.VERSION4_OPTIONS_WITHOUT_TIMESTAMP);
-        runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_BUFFER,
-                BinaryDictUtils.VERSION4_OPTIONS_WITH_TIMESTAMP);
 
         for (final String result : results) {
             Log.d(TAG, result);
diff --git a/tests/src/com/android/inputmethod/latin/makedict/SparseTableTests.java b/tests/src/com/android/inputmethod/latin/makedict/SparseTableTests.java
deleted file mode 100644
index aeb8552..0000000
--- a/tests/src/com/android/inputmethod/latin/makedict/SparseTableTests.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.latin.makedict;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Random;
-
-/**
- * Unit tests for SparseTable.
- */
-@LargeTest
-public class SparseTableTests extends AndroidTestCase {
-    private static final String TAG = SparseTableTests.class.getSimpleName();
-
-    private final Random mRandom;
-    private final ArrayList<Integer> mRandomIndex;
-
-    private static final int DEFAULT_SIZE = 10000;
-    private static final int BLOCK_SIZE = 8;
-
-    public SparseTableTests() {
-        this(System.currentTimeMillis(), DEFAULT_SIZE);
-    }
-
-    public SparseTableTests(final long seed, final int tableSize) {
-        super();
-        Log.d(TAG, "Seed for test is " + seed + ", size is " + tableSize);
-        mRandom = new Random(seed);
-        mRandomIndex = new ArrayList<Integer>(tableSize);
-        for (int i = 0; i < tableSize; ++i) {
-            mRandomIndex.add(SparseTable.NOT_EXIST);
-        }
-    }
-
-    public void testSet() {
-        final SparseTable table = new SparseTable(16, BLOCK_SIZE, 1);
-        table.set(0, 3, 6);
-        table.set(0, 8, 16);
-        for (int i = 0; i < 16; ++i) {
-            if (i == 3 || i == 8) {
-                assertEquals(i * 2, table.get(0, i));
-            } else {
-                assertEquals(SparseTable.NOT_EXIST, table.get(0, i));
-            }
-        }
-    }
-
-    private void generateRandomIndex(final int size, final int prop) {
-        for (int i = 0; i < size; ++i) {
-            if (mRandom.nextInt(100) < prop) {
-                mRandomIndex.set(i, mRandom.nextInt());
-            } else {
-                mRandomIndex.set(i, SparseTable.NOT_EXIST);
-            }
-        }
-    }
-
-    private void runTestRandomSet() {
-        final SparseTable table = new SparseTable(DEFAULT_SIZE, BLOCK_SIZE, 1);
-        int elementCount = 0;
-        for (int i = 0; i < DEFAULT_SIZE; ++i) {
-            if (mRandomIndex.get(i) != SparseTable.NOT_EXIST) {
-                table.set(0, i, mRandomIndex.get(i));
-                elementCount++;
-            }
-        }
-
-        Log.d(TAG, "table size = " + table.getLookupTableSize() + " + "
-              + table.getContentTableSize());
-        Log.d(TAG, "the table has " + elementCount + " elements");
-        for (int i = 0; i < DEFAULT_SIZE; ++i) {
-            assertEquals(table.get(0, i), (int)mRandomIndex.get(i));
-        }
-
-        // flush and reload
-        OutputStream lookupOutStream = null;
-        OutputStream contentOutStream = null;
-        try {
-            final File lookupIndexFile = File.createTempFile("testRandomSet", ".small");
-            final File contentFile = File.createTempFile("testRandomSet", ".big");
-            lookupOutStream = new FileOutputStream(lookupIndexFile);
-            contentOutStream = new FileOutputStream(contentFile);
-            table.write(lookupOutStream, new OutputStream[] { contentOutStream });
-            lookupOutStream.flush();
-            contentOutStream.flush();
-            final SparseTable newTable = SparseTable.readFromFiles(lookupIndexFile,
-                    new File[] { contentFile }, BLOCK_SIZE);
-            for (int i = 0; i < DEFAULT_SIZE; ++i) {
-                assertEquals(table.get(0, i), newTable.get(0, i));
-            }
-        } catch (IOException e) {
-            Log.d(TAG, "IOException while flushing and realoding", e);
-        } finally {
-            if (lookupOutStream != null) {
-                try {
-                    lookupOutStream.close();
-                } catch (IOException e) {
-                    Log.d(TAG, "IOException while closing the stream", e);
-                }
-            }
-            if (contentOutStream != null) {
-                try {
-                    contentOutStream.close();
-                } catch (IOException e) {
-                    Log.d(TAG, "IOException while closing contentStream.", e);
-                }
-            }
-        }
-    }
-
-    public void testRandomSet() {
-        for (int i = 0; i <= 100; i += 10) {
-            generateRandomIndex(DEFAULT_SIZE, i);
-            runTestRandomSet();
-        }
-    }
-
-    public void testMultipleContents() {
-        final int numOfContents = 5;
-        generateRandomIndex(DEFAULT_SIZE, 20);
-        final SparseTable table = new SparseTable(DEFAULT_SIZE, BLOCK_SIZE, numOfContents);
-        for (int i = 0; i < mRandomIndex.size(); ++i) {
-            if (mRandomIndex.get(i) != SparseTable.NOT_EXIST) {
-                for (int j = 0; j < numOfContents; ++j) {
-                    table.set(j, i, mRandomIndex.get(i));
-                }
-            }
-        }
-
-        OutputStream lookupOutStream = null;
-        OutputStream[] contentsOutStream = new OutputStream[numOfContents];
-        try {
-            final File lookupIndexFile = File.createTempFile("testMultipleContents", "small");
-            lookupOutStream = new FileOutputStream(lookupIndexFile);
-            final File[] contentFiles = new File[numOfContents];
-            for (int i = 0; i < numOfContents; ++i) {
-                contentFiles[i] = File.createTempFile("testMultipleContents", "big" + i);
-                contentsOutStream[i] = new FileOutputStream(contentFiles[i]);
-            }
-            table.write(lookupOutStream, contentsOutStream);
-            lookupOutStream.flush();
-            for (int i = 0; i < numOfContents; ++i) {
-                contentsOutStream[i].flush();
-            }
-            final SparseTable newTable = SparseTable.readFromFiles(lookupIndexFile, contentFiles,
-                    BLOCK_SIZE);
-            for (int i = 0; i < numOfContents; ++i) {
-                for (int j = 0; j < DEFAULT_SIZE; ++j) {
-                    assertEquals(table.get(i, j), newTable.get(i, j));
-                }
-            }
-        } catch (IOException e) {
-            Log.d(TAG, "IOException while flushing and reloading", e);
-        } finally {
-            if (lookupOutStream != null) {
-                try {
-                    lookupOutStream.close();
-                } catch (IOException e) {
-                    Log.d(TAG, "IOException while closing the stream", e);
-                }
-            }
-            for (int i = 0; i < numOfContents; ++i) {
-                if (contentsOutStream[i] != null) {
-                    try {
-                        contentsOutStream[i].close();
-                    } catch (IOException e) {
-                        Log.d(TAG, "IOException while closing the stream.", e);
-                    }
-                }
-            }
-        }
-    }
-}
diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk
index adfb920..b83ce57 100644
--- a/tools/dicttool/Android.mk
+++ b/tools/dicttool/Android.mk
@@ -43,13 +43,13 @@
         $(LATINIME_CORE_SOURCE_DIRECTORY)/settings/NativeSuggestOptions.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/ByteArrayDictBuffer.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CollectionUtils.java \
+        $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CombinedFormatUtils.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CoordinateUtils.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/FileUtils.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/JniUtils.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/LocaleUtils.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/ResizableIntArray.java \
-        $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/StringUtils.java \
-        $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/WordProperty.java
+        $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/StringUtils.java
 
 DICTTOOL_ONDEVICE_TESTS_DIRECTORY := \
         $(LATINIME_LOCAL_DIR)/tests/src/com/android/inputmethod/latin/makedict/
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java
index b984060..8d2f5fb 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java
@@ -21,7 +21,8 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
+import com.android.inputmethod.latin.utils.CombinedFormatUtils;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -41,16 +42,10 @@
  * All functions in this class are static.
  */
 public class CombinedInputOutput {
-
-    private static final String DICTIONARY_TAG = "dictionary";
-    private static final String BIGRAM_TAG = "bigram";
-    private static final String SHORTCUT_TAG = "shortcut";
-    private static final String FREQUENCY_TAG = "f";
-    private static final String WORD_TAG = "word";
-    private static final String NOT_A_WORD_TAG = "not_a_word";
     private static final String WHITELIST_TAG = "whitelist";
     private static final String OPTIONS_TAG = "options";
     private static final String COMMENT_LINE_STARTER = "#";
+    private static final int HISTORICAL_INFO_ELEMENT_COUNT = 3;
 
     /**
      * Basic test to find out whether the file is in the combined format or not.
@@ -68,7 +63,8 @@
             while (firstLine.startsWith(COMMENT_LINE_STARTER)) {
                 firstLine = reader.readLine();
             }
-            return firstLine.matches("^" + DICTIONARY_TAG + "=[^:]+(:[^=]+=[^:]+)*");
+            return firstLine.matches(
+                    "^" + CombinedFormatUtils.DICTIONARY_TAG + "=[^:]+(:[^=]+=[^:]+)*");
         } catch (FileNotFoundException e) {
             return false;
         } catch (IOException e) {
@@ -123,7 +119,7 @@
         while (null != (line = reader.readLine())) {
             if (line.startsWith(COMMENT_LINE_STARTER)) continue;
             final String args[] = line.trim().split(",");
-            if (args[0].matches(WORD_TAG + "=.*")) {
+            if (args[0].matches(CombinedFormatUtils.WORD_TAG + "=.*")) {
                 if (null != word) {
                     dict.add(word, freq, shortcuts.isEmpty() ? null : shortcuts, isNotAWord);
                     for (WeightedString s : bigrams) {
@@ -136,23 +132,30 @@
                 for (String param : args) {
                     final String params[] = param.split("=", 2);
                     if (2 != params.length) throw new RuntimeException("Wrong format : " + line);
-                    if (WORD_TAG.equals(params[0])) {
+                    if (CombinedFormatUtils.WORD_TAG.equals(params[0])) {
                         word = params[1];
-                    } else if (FREQUENCY_TAG.equals(params[0])) {
+                    } else if (CombinedFormatUtils.PROBABILITY_TAG.equals(params[0])) {
                         freq = Integer.parseInt(params[1]);
-                    } else if (NOT_A_WORD_TAG.equals(params[0])) {
+                    } else if (CombinedFormatUtils.HISTORICAL_INFO_TAG.equals(params[0])) {
+                        final String[] historicalInfoParams =
+                                params[1].split(CombinedFormatUtils.HISTORICAL_INFO_SEPARATOR);
+                        if (historicalInfoParams.length != HISTORICAL_INFO_ELEMENT_COUNT) {
+                            throw new RuntimeException("Wrong format (historical info) : " + line);
+                        }
+                        // TODO: Use parsed historical info.
+                    } else if (CombinedFormatUtils.NOT_A_WORD_TAG.equals(params[0])) {
                         isNotAWord = "true".equals(params[1]);
                     }
                 }
-            } else if (args[0].matches(SHORTCUT_TAG + "=.*")) {
+            } else if (args[0].matches(CombinedFormatUtils.SHORTCUT_TAG + "=.*")) {
                 String shortcut = null;
                 int shortcutFreq = 0;
                 for (String param : args) {
                     final String params[] = param.split("=", 2);
                     if (2 != params.length) throw new RuntimeException("Wrong format : " + line);
-                    if (SHORTCUT_TAG.equals(params[0])) {
+                    if (CombinedFormatUtils.SHORTCUT_TAG.equals(params[0])) {
                         shortcut = params[1];
-                    } else if (FREQUENCY_TAG.equals(params[0])) {
+                    } else if (CombinedFormatUtils.PROBABILITY_TAG.equals(params[0])) {
                         shortcutFreq = WHITELIST_TAG.equals(params[1])
                                 ? FormatSpec.SHORTCUT_WHITELIST_FREQUENCY
                                 : Integer.parseInt(params[1]);
@@ -163,16 +166,23 @@
                 } else {
                     throw new RuntimeException("Wrong format : " + line);
                 }
-            } else if (args[0].matches(BIGRAM_TAG + "=.*")) {
+            } else if (args[0].matches(CombinedFormatUtils.BIGRAM_TAG + "=.*")) {
                 String secondWordOfBigram = null;
                 int bigramFreq = 0;
                 for (String param : args) {
                     final String params[] = param.split("=", 2);
                     if (2 != params.length) throw new RuntimeException("Wrong format : " + line);
-                    if (BIGRAM_TAG.equals(params[0])) {
+                    if (CombinedFormatUtils.BIGRAM_TAG.equals(params[0])) {
                         secondWordOfBigram = params[1];
-                    } else if (FREQUENCY_TAG.equals(params[0])) {
+                    } else if (CombinedFormatUtils.PROBABILITY_TAG.equals(params[0])) {
                         bigramFreq = Integer.parseInt(params[1]);
+                    }  else if (CombinedFormatUtils.HISTORICAL_INFO_TAG.equals(params[0])) {
+                        final String[] historicalInfoParams =
+                                params[1].split(CombinedFormatUtils.HISTORICAL_INFO_SEPARATOR);
+                        if (historicalInfoParams.length != HISTORICAL_INFO_ELEMENT_COUNT) {
+                            throw new RuntimeException("Wrong format (historical info) : " + line);
+                        }
+                        // TODO: Use parsed historical info.
                     }
                 }
                 if (null != secondWordOfBigram) {
@@ -198,39 +208,16 @@
      * @param destination a destination stream to write to.
      * @param dict the dictionary to write.
      */
-    public static void writeDictionaryCombined(Writer destination, FusionDictionary dict)
-            throws IOException {
-        final TreeSet<Word> set = new TreeSet<Word>();
-        for (Word word : dict) {
-            set.add(word); // This for ordering by frequency, then by asciibetic order
+    public static void writeDictionaryCombined(
+            final Writer destination, final FusionDictionary dict) throws IOException {
+        final TreeSet<WordProperty> wordPropertiesInDict = new TreeSet<WordProperty>();
+        for (final WordProperty wordProperty : dict) {
+            // This for ordering by frequency, then by asciibetic order
+            wordPropertiesInDict.add(wordProperty);
         }
-        final HashMap<String, String> options = dict.mOptions.mAttributes;
-        destination.write(DICTIONARY_TAG + "=");
-        if (options.containsKey(DICTIONARY_TAG)) {
-            destination.write(options.get(DICTIONARY_TAG));
-            options.remove(DICTIONARY_TAG);
-        }
-        for (final String key : dict.mOptions.mAttributes.keySet()) {
-            final String value = dict.mOptions.mAttributes.get(key);
-            destination.write("," + key + "=" + value);
-        }
-        destination.write("\n");
-        for (Word word : set) {
-            destination.write(" " + WORD_TAG + "=" + word.mWord + ","
-                    + FREQUENCY_TAG + "=" + word.mFrequency
-                    + (word.mIsNotAWord ? "," + NOT_A_WORD_TAG + "=true\n" : "\n"));
-            if (null != word.mShortcutTargets) {
-                for (WeightedString target : word.mShortcutTargets) {
-                    destination.write("  " + SHORTCUT_TAG + "=" + target.mWord + ","
-                            + FREQUENCY_TAG + "=" + target.getProbability() + "\n");
-                }
-            }
-            if (null != word.mBigrams) {
-                for (WeightedString bigram : word.mBigrams) {
-                    destination.write("  " + BIGRAM_TAG + "=" + bigram.mWord + ","
-                            + FREQUENCY_TAG + "=" + bigram.getProbability() + "\n");
-                }
-            }
+        destination.write(CombinedFormatUtils.formatAttributeMap(dict.mOptions.mAttributes));
+        for (final WordProperty wordProperty : wordPropertiesInDict) {
+            destination.write(CombinedFormatUtils.formatWordProperty(wordProperty));
         }
         destination.close();
     }
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java
index c9f6bd5..9947608 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java
@@ -19,7 +19,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import java.util.Arrays;
 import java.util.ArrayList;
@@ -108,42 +108,46 @@
 
     private static void diffWords(final FusionDictionary dict0, final FusionDictionary dict1) {
         boolean hasDifferences = false;
-        for (final Word word0 : dict0) {
-            final PtNode word1 = FusionDictionary.findWordInTree(dict1.mRootNodeArray,
-                    word0.mWord);
-            if (null == word1) {
+        for (final WordProperty word0Property : dict0) {
+            final PtNode word1PtNode = FusionDictionary.findWordInTree(dict1.mRootNodeArray,
+                    word0Property.mWord);
+            if (null == word1PtNode) {
                 // This word is not in dict1
-                System.out.println("Deleted: " + word0.mWord + " " + word0.mFrequency);
+                System.out.println("Deleted: " + word0Property.mWord + " "
+                        + word0Property.getProbability());
                 hasDifferences = true;
             } else {
                 // We found the word. Compare frequencies, shortcuts, bigrams
-                if (word0.mFrequency != word1.getFrequency()) {
-                    System.out.println("Freq changed: " + word0.mWord + " " + word0.mFrequency
-                            + " -> " + word1.getFrequency());
+                if (word0Property.getProbability() != word1PtNode.getFrequency()) {
+                    System.out.println("Probability changed: " + word0Property.mWord + " "
+                            + word0Property.getProbability() + " -> " + word1PtNode.getFrequency());
                     hasDifferences = true;
                 }
-                if (word0.mIsNotAWord != word1.getIsNotAWord()) {
-                    System.out.println("Not a word: " + word0.mWord + " " + word0.mIsNotAWord
-                            + " -> " + word1.getIsNotAWord());
+                if (word0Property.mIsNotAWord != word1PtNode.getIsNotAWord()) {
+                    System.out.println("Not a word: " + word0Property.mWord + " "
+                            + word0Property.mIsNotAWord + " -> " + word1PtNode.getIsNotAWord());
                     hasDifferences = true;
                 }
-                if (word0.mIsBlacklistEntry != word1.getIsBlacklistEntry()) {
-                    System.out.println("Blacklist: " + word0.mWord + " " + word0.mIsBlacklistEntry
-                            + " -> " + word1.getIsBlacklistEntry());
+                if (word0Property.mIsBlacklistEntry != word1PtNode.getIsBlacklistEntry()) {
+                    System.out.println("Blacklist: " + word0Property.mWord + " "
+                            + word0Property.mIsBlacklistEntry + " -> "
+                            + word1PtNode.getIsBlacklistEntry());
                     hasDifferences = true;
                 }
-                hasDifferences |= hasAttributesDifferencesAndPrintThemIfAny(word0.mWord,
-                        "Bigram", word0.mBigrams, word1.getBigrams());
-                hasDifferences |= hasAttributesDifferencesAndPrintThemIfAny(word0.mWord,
-                        "Shortcut", word0.mShortcutTargets, word1.getShortcutTargets());
+                hasDifferences |= hasAttributesDifferencesAndPrintThemIfAny(word0Property.mWord,
+                        "Bigram", word0Property.mBigrams, word1PtNode.getBigrams());
+                hasDifferences |= hasAttributesDifferencesAndPrintThemIfAny(word0Property.mWord,
+                        "Shortcut", word0Property.mShortcutTargets,
+                        word1PtNode.getShortcutTargets());
             }
         }
-        for (final Word word1 : dict1) {
-            final PtNode word0 = FusionDictionary.findWordInTree(dict0.mRootNodeArray,
-                    word1.mWord);
-            if (null == word0) {
+        for (final WordProperty word1Property : dict1) {
+            final PtNode word0PtNode = FusionDictionary.findWordInTree(dict0.mRootNodeArray,
+                    word1Property.mWord);
+            if (null == word0PtNode) {
                 // This word is not in dict0
-                System.out.println("Added: " + word1.mWord + " " + word1.mFrequency);
+                System.out.println("Added: " + word1Property.mWord + " "
+                        + word1Property.getProbability());
                 hasDifferences = true;
             }
         }
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Info.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Info.java
index 8f17fcd..c1eb0f8 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Info.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Info.java
@@ -20,7 +20,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import java.util.Arrays;
 import java.util.ArrayList;
@@ -43,14 +43,14 @@
         int bigramCount = 0;
         int shortcutCount = 0;
         int whitelistCount = 0;
-        for (final Word w : dict) {
+        for (final WordProperty wordProperty : dict) {
             ++wordCount;
-            if (null != w.mBigrams) {
-                bigramCount += w.mBigrams.size();
+            if (null != wordProperty.mBigrams) {
+                bigramCount += wordProperty.mBigrams.size();
             }
-            if (null != w.mShortcutTargets) {
-                shortcutCount += w.mShortcutTargets.size();
-                for (WeightedString shortcutTarget : w.mShortcutTargets) {
+            if (null != wordProperty.mShortcutTargets) {
+                shortcutCount += wordProperty.mShortcutTargets.size();
+                for (WeightedString shortcutTarget : wordProperty.mShortcutTargets) {
                     if (FormatSpec.SHORTCUT_WHITELIST_FREQUENCY
                             == shortcutTarget.getProbability()) {
                         ++whitelistCount;
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java
index cdc487b..c6c60b8 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java
@@ -20,7 +20,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -52,7 +52,7 @@
     private static final String WORD_TAG = "w";
     private static final String BIGRAM_TAG = "bigram";
     private static final String SHORTCUT_TAG = "shortcut";
-    private static final String FREQUENCY_ATTR = "f";
+    private static final String PROBABILITY_ATTR = "f";
     private static final String WORD_ATTR = "word";
     private static final String NOT_A_WORD_ATTR = "not_a_word";
 
@@ -107,7 +107,7 @@
                 mWord = "";
                 for (int attrIndex = 0; attrIndex < attrs.getLength(); ++attrIndex) {
                     final String attrName = attrs.getLocalName(attrIndex);
-                    if (FREQUENCY_ATTR.equals(attrName)) {
+                    if (PROBABILITY_ATTR.equals(attrName)) {
                         mFreq = Integer.parseInt(attrs.getValue(attrIndex));
                     }
                 }
@@ -348,9 +348,9 @@
      */
     public static void writeDictionaryXml(Writer destination, FusionDictionary dict)
             throws IOException {
-        final TreeSet<Word> set = new TreeSet<Word>();
-        for (Word word : dict) {
-            set.add(word);
+        final TreeSet<WordProperty> wordPropertiesInDict = new TreeSet<WordProperty>();
+        for (WordProperty wordProperty : dict) {
+            wordPropertiesInDict.add(wordProperty);
         }
         // TODO: use an XMLSerializer if this gets big
         destination.write("<wordlist format=\"2\"");
@@ -361,23 +361,24 @@
         }
         destination.write(">\n");
         destination.write("<!-- Warning: there is no code to read this format yet. -->\n");
-        for (Word word : set) {
-            destination.write("  <" + WORD_TAG + " " + WORD_ATTR + "=\"" + word.mWord + "\" "
-                    + FREQUENCY_ATTR + "=\"" + word.mFrequency
-                    + (word.mIsNotAWord ? "\" " + NOT_A_WORD_ATTR + "=\"true" : "") + "\">");
-            if (null != word.mShortcutTargets) {
+        for (WordProperty wordProperty : wordPropertiesInDict) {
+            destination.write("  <" + WORD_TAG + " " + WORD_ATTR + "=\"" + wordProperty.mWord
+                    + "\" " + PROBABILITY_ATTR + "=\"" + wordProperty.getProbability()
+                    + (wordProperty.mIsNotAWord ? "\" " + NOT_A_WORD_ATTR + "=\"true" : "")
+                    + "\">");
+            if (null != wordProperty.mShortcutTargets) {
                 destination.write("\n");
-                for (WeightedString target : word.mShortcutTargets) {
-                    destination.write("    <" + SHORTCUT_TAG + " " + FREQUENCY_ATTR + "=\""
+                for (WeightedString target : wordProperty.mShortcutTargets) {
+                    destination.write("    <" + SHORTCUT_TAG + " " + PROBABILITY_ATTR + "=\""
                             + target.getProbability() + "\">" + target.mWord + "</" + SHORTCUT_TAG
                             + ">\n");
                 }
                 destination.write("  ");
             }
-            if (null != word.mBigrams) {
+            if (null != wordProperty.mBigrams) {
                 destination.write("\n");
-                for (WeightedString bigram : word.mBigrams) {
-                    destination.write("    <" + BIGRAM_TAG + " " + FREQUENCY_ATTR + "=\""
+                for (WeightedString bigram : wordProperty.mBigrams) {
+                    destination.write("    <" + BIGRAM_TAG + " " + PROBABILITY_ATTR + "=\""
                             + bigram.getProbability() + "\">" + bigram.mWord
                             + "</" + BIGRAM_TAG + ">\n");
                 }
diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
index 76dadc2..1915464 100644
--- a/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
+++ b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
@@ -20,7 +20,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import junit.framework.TestCase;
 
@@ -87,8 +87,8 @@
     }
 
     private void dumpDict(final FusionDictionary dict) {
-        for (Word w : dict) {
-            System.out.println("Word " + dumpWord(w.mWord));
+        for (WordProperty wordProperty : dict) {
+            System.out.println("Word " + dumpWord(wordProperty.mWord));
         }
     }
 
diff --git a/tools/make-keyboard-text/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl b/tools/make-keyboard-text/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl
index db1dde3..7a6284f 100644
--- a/tools/make-keyboard-text/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl
+++ b/tools/make-keyboard-text/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl
@@ -25,6 +25,7 @@
 import com.android.inputmethod.latin.utils.CollectionUtils;
 
 import java.util.HashMap;
+import java.util.Locale;
 
 /**
  * !!!!! DO NOT EDIT THIS FILE !!!!!
@@ -52,15 +53,17 @@
     private static final int MAX_STRING_REFERENCE_INDIRECTION = 10;
 
     // Language to texts map.
-    private static final HashMap<String, String[]> sLocaleToTextsMap = CollectionUtils.newHashMap();
+    private static final HashMap<String, String[]> sLanguageToTextsMap =
+            CollectionUtils.newHashMap();
     private static final HashMap<String, Integer> sNameToIdsMap = CollectionUtils.newHashMap();
 
     private String[] mTexts;
     // Resource name to text map.
     private HashMap<String, String> mResourceNameToTextsMap = CollectionUtils.newHashMap();
 
-    public void setLanguage(final String language) {
-        mTexts = sLocaleToTextsMap.get(language);
+    public void setLocale(final Locale locale) {
+        final String language = locale.getLanguage();
+        mTexts = sLanguageToTextsMap.get(language);
         if (mTexts == null) {
             mTexts = LANGUAGE_DEFAULT;
         }
@@ -195,7 +198,7 @@
         for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
             final String language = (String)LANGUAGES_AND_TEXTS[i];
             final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
-            sLocaleToTextsMap.put(language, texts);
+            sLanguageToTextsMap.put(language, texts);
         }
     }
 }
diff --git a/tools/make-keyboard-text/res/values/donottranslate-more-keys.xml b/tools/make-keyboard-text/res/values/donottranslate-more-keys.xml
index ceb46dc..2b7ef7c 100644
--- a/tools/make-keyboard-text/res/values/donottranslate-more-keys.xml
+++ b/tools/make-keyboard-text/res/values/donottranslate-more-keys.xml
@@ -215,7 +215,6 @@
     <string name="keylabel_for_popular_domain">".com"</string>
     <!-- popular web domains for the locale - most popular, displayed on the keyboard -->
     <string name="more_keys_for_popular_domain">"!hasLabels!,.net,.org,.gov,.edu"</string>
-    <string name="more_keys_for_smiley">"!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ "</string>
     <!-- U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK
          U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
          U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK