Updated implementation to match native behaviour more closely.