diff --git a/Cargo.lock b/Cargo.lock
index d9865b4854bcc29a2bc6f1d3dfd5b96b2b0b0445..ab5b5513810765685636e5b7df72476710f21b08 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1545,14 +1545,14 @@ dependencies = [
 [[package]]
 name = "ruma"
 version = "0.1.0"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "ruma-api",
  "ruma-client-api",
  "ruma-common",
  "ruma-events",
  "ruma-federation-api",
- "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
+ "ruma-identifiers",
  "ruma-identifiers-macros",
  "ruma-signatures",
 ]
@@ -1560,12 +1560,12 @@ dependencies = [
 [[package]]
 name = "ruma-api"
 version = "0.16.1"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "http",
  "percent-encoding",
  "ruma-api-macros",
- "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
+ "ruma-identifiers",
  "ruma-serde",
  "serde",
  "serde_json",
@@ -1575,7 +1575,7 @@ dependencies = [
 [[package]]
 name = "ruma-api-macros"
 version = "0.16.1"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -1585,14 +1585,14 @@ dependencies = [
 [[package]]
 name = "ruma-client-api"
 version = "0.9.0"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "http",
  "js_int",
  "ruma-api",
  "ruma-common",
  "ruma-events",
- "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
+ "ruma-identifiers",
  "ruma-serde",
  "serde",
  "serde_json",
@@ -1602,7 +1602,7 @@ dependencies = [
 [[package]]
 name = "ruma-common"
 version = "0.2.0"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "js_int",
  "ruma-serde",
@@ -1614,12 +1614,12 @@ dependencies = [
 [[package]]
 name = "ruma-events"
 version = "0.21.3"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "js_int",
  "ruma-common",
  "ruma-events-macros",
- "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
+ "ruma-identifiers",
  "ruma-serde",
  "serde",
  "serde_json",
@@ -1629,7 +1629,7 @@ dependencies = [
 [[package]]
 name = "ruma-events-macros"
 version = "0.21.3"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -1639,13 +1639,13 @@ dependencies = [
 [[package]]
 name = "ruma-federation-api"
 version = "0.0.2"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "js_int",
  "ruma-api",
  "ruma-common",
  "ruma-events",
- "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)",
+ "ruma-identifiers",
  "ruma-serde",
  "serde",
  "serde_json",
@@ -1653,39 +1653,29 @@ dependencies = [
 
 [[package]]
 name = "ruma-identifiers"
-version = "0.17.0"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+version = "0.17.1"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "rand",
  "serde",
  "strum",
 ]
 
-[[package]]
-name = "ruma-identifiers"
-version = "0.17.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f7046d6ff26cf4f5b8bc77af68527544c61e32cab5810c40035c6491c08da0d3"
-dependencies = [
- "serde",
- "strum",
-]
-
 [[package]]
 name = "ruma-identifiers-macros"
-version = "0.17.0"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+version = "0.17.1"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "proc-macro2",
  "quote",
- "ruma-identifiers 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ruma-identifiers",
  "syn",
 ]
 
 [[package]]
 name = "ruma-serde"
 version = "0.2.2"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "form_urlencoded",
  "itoa",
@@ -1697,7 +1687,7 @@ dependencies = [
 [[package]]
 name = "ruma-signatures"
 version = "0.6.0-dev.1"
-source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2"
+source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
 dependencies = [
  "base64 0.12.3",
  "ring",
diff --git a/Cargo.toml b/Cargo.toml
index e0f246edb8ece1ca59f47d6877e3589f4c714542..ec1ee6300fbd9877b97d4f69f1b37dee862d47bc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,4 +27,4 @@ reqwest = "0.10.6"
 base64 = "0.12.1"
 thiserror = "1.0.19"
 image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] }
-ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "08fbace" }
+ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "e047c647ddcb368e7eb1e05ae8823a9494273457" }
diff --git a/src/client_server.rs b/src/client_server.rs
index 0c085e36f5da00ff8db57107bf8a7dc6e7d81628..3083ff240ebae07fabfd58e0504cb346cf2d7c16 100644
--- a/src/client_server.rs
+++ b/src/client_server.rs
@@ -64,10 +64,9 @@
             canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction,
             topic,
         },
-        AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventJson,
-        EventType,
+        AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventType,
     },
-    identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId},
+    Raw, RoomAliasId, RoomId, RoomVersionId, UserId,
 };
 use serde_json::json;
 
@@ -624,7 +623,7 @@ pub fn set_displayname_route(
             EventType::RoomMember,
             serde_json::to_value(ruma::events::room::member::MemberEventContent {
                 displayname: body.displayname.clone(),
-                ..serde_json::from_value::<EventJson<_>>(
+                ..serde_json::from_value::<Raw<_>>(
                     db.rooms
                         .room_state_get(&room_id, &EventType::RoomMember, &user_id.to_string())?
                         .ok_or_else(|| {
@@ -659,7 +658,7 @@ pub fn set_displayname_route(
                         .try_into()
                         .expect("time is valid"),
                 ),
-                presence: ruma::events::presence::PresenceState::Online,
+                presence: ruma::presence::PresenceState::Online,
                 status_msg: None,
             },
             sender: user_id.clone(),
@@ -714,7 +713,7 @@ pub fn set_avatar_url_route(
             EventType::RoomMember,
             serde_json::to_value(ruma::events::room::member::MemberEventContent {
                 avatar_url: body.avatar_url.clone(),
-                ..serde_json::from_value::<EventJson<_>>(
+                ..serde_json::from_value::<Raw<_>>(
                     db.rooms
                         .room_state_get(&room_id, &EventType::RoomMember, &user_id.to_string())?
                         .ok_or_else(|| {
@@ -749,7 +748,7 @@ pub fn set_avatar_url_route(
                         .try_into()
                         .expect("time is valid"),
                 ),
-                presence: ruma::events::presence::PresenceState::Online,
+                presence: ruma::presence::PresenceState::Online,
                 status_msg: None,
             },
             sender: user_id.clone(),
@@ -1605,7 +1604,7 @@ pub fn leave_room_route(
 ) -> ConduitResult<leave_room::Response> {
     let user_id = body.user_id.as_ref().expect("user is authenticated");
 
-    let mut event = serde_json::from_value::<EventJson<member::MemberEventContent>>(
+    let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
         db.rooms
             .room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
             .ok_or(Error::BadRequest(
@@ -1643,20 +1642,19 @@ pub fn kick_user_route(
 ) -> ConduitResult<kick_user::Response> {
     let user_id = body.user_id.as_ref().expect("user is authenticated");
 
-    let mut event =
-        serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>(
-            db.rooms
-                .room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
-                .ok_or(Error::BadRequest(
-                    ErrorKind::BadState,
-                    "Cannot kick member that's not in the room.",
-                ))?
-                .content
-                .clone(),
-        )
-        .map_err(|_| Error::bad_database("Invalid member event in database."))?
-        .deserialize()
-        .map_err(|_| Error::bad_database("Invalid member event in database."))?;
+    let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
+        db.rooms
+            .room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
+            .ok_or(Error::BadRequest(
+                ErrorKind::BadState,
+                "Cannot kick member that's not in the room.",
+            ))?
+            .content
+            .clone(),
+    )
+    .map_err(|_| Error::bad_database("Invalid member event in database."))?
+    .deserialize()
+    .map_err(|_| Error::bad_database("Invalid member event in database."))?;
 
     event.membership = ruma::events::room::member::MembershipState::Leave;
     // TODO: reason
@@ -1697,7 +1695,7 @@ pub fn ban_user_route(
                 third_party_invite: None,
             }),
             |event| {
-                let mut event = serde_json::from_value::<EventJson<member::MemberEventContent>>(
+                let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
                     event.content.clone(),
                 )
                 .map_err(|_| Error::bad_database("Invalid member event in database."))?
@@ -1730,20 +1728,19 @@ pub fn unban_user_route(
 ) -> ConduitResult<unban_user::Response> {
     let user_id = body.user_id.as_ref().expect("user is authenticated");
 
-    let mut event =
-        serde_json::from_value::<EventJson<ruma::events::room::member::MemberEventContent>>(
-            db.rooms
-                .room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
-                .ok_or(Error::BadRequest(
-                    ErrorKind::BadState,
-                    "Cannot unban a user who is not banned.",
-                ))?
-                .content
-                .clone(),
-        )
-        .map_err(|_| Error::bad_database("Invalid member event in database."))?
-        .deserialize()
-        .map_err(|_| Error::bad_database("Invalid member event in database."))?;
+    let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
+        db.rooms
+            .room_state_get(&body.room_id, &EventType::RoomMember, &user_id.to_string())?
+            .ok_or(Error::BadRequest(
+                ErrorKind::BadState,
+                "Cannot unban a user who is not banned.",
+            ))?
+            .content
+            .clone(),
+    )
+    .map_err(|_| Error::bad_database("Invalid member event in database."))?
+    .deserialize()
+    .map_err(|_| Error::bad_database("Invalid member event in database."))?;
 
     event.membership = ruma::events::room::member::MembershipState::Leave;
 
@@ -1902,7 +1899,7 @@ pub async fn get_public_rooms_filtered_route(
                 aliases: Vec::new(),
                 canonical_alias: state.get(&(EventType::RoomCanonicalAlias, "".to_owned())).map_or(Ok::<_, Error>(None), |s| {
                     Ok(serde_json::from_value::<
-                            EventJson<ruma::events::room::canonical_alias::CanonicalAliasEventContent>,
+                            Raw<ruma::events::room::canonical_alias::CanonicalAliasEventContent>,
                         >(s.content.clone())
                         .map_err(|_| Error::bad_database("Invalid canonical alias event in database."))?
                         .deserialize()
@@ -1910,7 +1907,7 @@ pub async fn get_public_rooms_filtered_route(
                         .alias)
                 })?,
                 name: state.get(&(EventType::RoomName, "".to_owned())).map_or(Ok::<_, Error>(None), |s| {
-                    Ok(serde_json::from_value::<EventJson<ruma::events::room::name::NameEventContent>>(
+                    Ok(serde_json::from_value::<Raw<ruma::events::room::name::NameEventContent>>(
                         s.content.clone(),
                     )
                     .map_err(|_| Error::bad_database("Invalid room name event in database."))?
@@ -1923,7 +1920,7 @@ pub async fn get_public_rooms_filtered_route(
                 room_id,
                 topic: state.get(&(EventType::RoomTopic, "".to_owned())).map_or(Ok::<_, Error>(None), |s| {
                     Ok(Some(serde_json::from_value::<
-                            EventJson<ruma::events::room::topic::TopicEventContent>,
+                            Raw<ruma::events::room::topic::TopicEventContent>,
                         >(s.content.clone())
                         .map_err(|_| Error::bad_database("Invalid room topic event in database."))?
                         .deserialize()
@@ -1932,7 +1929,7 @@ pub async fn get_public_rooms_filtered_route(
                 })?,
                 world_readable: state.get(&(EventType::RoomHistoryVisibility, "".to_owned())).map_or(Ok::<_, Error>(false), |s| {
                     Ok(serde_json::from_value::<
-                            EventJson<ruma::events::room::history_visibility::HistoryVisibilityEventContent>,
+                            Raw<ruma::events::room::history_visibility::HistoryVisibilityEventContent>,
                         >(s.content.clone())
                         .map_err(|_| Error::bad_database("Invalid room history visibility event in database."))?
                         .deserialize()
@@ -1941,7 +1938,7 @@ pub async fn get_public_rooms_filtered_route(
                 })?,
                 guest_can_join: state.get(&(EventType::RoomGuestAccess, "".to_owned())).map_or(Ok::<_, Error>(false), |s| {
                     Ok(serde_json::from_value::<
-                            EventJson<ruma::events::room::guest_access::GuestAccessEventContent>,
+                            Raw<ruma::events::room::guest_access::GuestAccessEventContent>,
                         >(s.content.clone())
                         .map_err(|_| Error::bad_database("Invalid room guest access event in database."))?
                         .deserialize()
@@ -1950,7 +1947,7 @@ pub async fn get_public_rooms_filtered_route(
                 })?,
                 avatar_url: state.get(&(EventType::RoomAvatar, "".to_owned())).map_or( Ok::<_, Error>(None),|s| {
                     Ok(Some(serde_json::from_value::<
-                            EventJson<ruma::events::room::avatar::AvatarEventContent>,
+                            Raw<ruma::events::room::avatar::AvatarEventContent>,
                         >(s.content.clone())
                         .map_err(|_| Error::bad_database("Invalid room avatar event in database."))?
                         .deserialize()
@@ -2158,7 +2155,7 @@ pub fn create_state_event_for_key_route(
 
     if body.event_type == EventType::RoomCanonicalAlias {
         let canonical_alias = serde_json::from_value::<
-            EventJson<canonical_alias::CanonicalAliasEventContent>,
+            Raw<canonical_alias::CanonicalAliasEventContent>,
         >(content.clone())
         .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid canonical alias."))?
         .deserialize()
@@ -2375,9 +2372,9 @@ pub fn sync_route(
                 send_member_count = true;
                 if !joined_since_last_sync && pdu.state_key == Some(user_id.to_string()) {
                     let content = serde_json::from_value::<
-                        EventJson<ruma::events::room::member::MemberEventContent>,
+                        Raw<ruma::events::room::member::MemberEventContent>,
                     >(pdu.content.clone())
-                    .expect("EventJson::from_value always works")
+                    .expect("Raw::from_value always works")
                     .deserialize()
                     .map_err(|_| Error::bad_database("Invalid PDU in database."))?;
                     if content.membership == ruma::events::room::member::MembershipState::Join {
@@ -2410,7 +2407,7 @@ pub fn sync_route(
                     .filter(|pdu| pdu.kind == EventType::RoomMember)
                     .map(|pdu| {
                         let content = serde_json::from_value::<
-                            EventJson<ruma::events::room::member::MemberEventContent>,
+                            Raw<ruma::events::room::member::MemberEventContent>,
                         >(pdu.content.clone())
                         .map_err(|_| Error::bad_database("Invalid member event in database."))?
                         .deserialize()
@@ -2418,7 +2415,7 @@ pub fn sync_route(
 
                         if let Some(state_key) = &pdu.state_key {
                             let current_content = serde_json::from_value::<
-                                EventJson<ruma::events::room::member::MemberEventContent>,
+                                Raw<ruma::events::room::member::MemberEventContent>,
                             >(
                                 members
                                     .get(state_key)
@@ -2660,7 +2657,8 @@ pub fn sync_route(
     }
 
     // Remove all to-device events the device received *last time*
-    db.users.remove_to_device_events(user_id, device_id, since)?;
+    db.users
+        .remove_to_device_events(user_id, device_id, since)?;
 
     Ok(sync_events::Response {
         next_batch,
diff --git a/src/database/account_data.rs b/src/database/account_data.rs
index 3b64ba74ca2c08c0f8628f32885d10bd5224c4b7..8397c1296aab3fafaac98e502bcfa710352c67e8 100644
--- a/src/database/account_data.rs
+++ b/src/database/account_data.rs
@@ -1,8 +1,8 @@
 use crate::{utils, Error, Result};
 use ruma::{
     api::client::error::ErrorKind,
-    events::{AnyEvent as EduEvent, EventJson, EventType},
-    identifiers::{RoomId, UserId},
+    events::{AnyEvent as EduEvent, EventType},
+    Raw, RoomId, UserId,
 };
 use std::{collections::HashMap, convert::TryFrom};
 
@@ -81,7 +81,7 @@ pub fn get(
         room_id: Option<&RoomId>,
         user_id: &UserId,
         kind: &EventType,
-    ) -> Result<Option<EventJson<EduEvent>>> {
+    ) -> Result<Option<Raw<EduEvent>>> {
         Ok(self.all(room_id, user_id)?.remove(kind))
     }
 
@@ -91,7 +91,7 @@ pub fn changes_since(
         room_id: Option<&RoomId>,
         user_id: &UserId,
         since: u64,
-    ) -> Result<HashMap<EventType, EventJson<EduEvent>>> {
+    ) -> Result<HashMap<EventType, Raw<EduEvent>>> {
         let mut userdata = HashMap::new();
 
         let mut prefix = room_id
@@ -121,7 +121,7 @@ pub fn changes_since(
                         .map_err(|_| Error::bad_database("RoomUserData ID in db is invalid."))?,
                     )
                     .map_err(|_| Error::bad_database("RoomUserData ID in db is invalid."))?,
-                    serde_json::from_slice::<EventJson<EduEvent>>(&v).map_err(|_| {
+                    serde_json::from_slice::<Raw<EduEvent>>(&v).map_err(|_| {
                         Error::bad_database("Database contains invalid account data.")
                     })?,
                 ))
@@ -139,7 +139,7 @@ pub fn all(
         &self,
         room_id: Option<&RoomId>,
         user_id: &UserId,
-    ) -> Result<HashMap<EventType, EventJson<EduEvent>>> {
+    ) -> Result<HashMap<EventType, Raw<EduEvent>>> {
         self.changes_since(room_id, user_id, 0)
     }
 }
diff --git a/src/database/global_edus.rs b/src/database/global_edus.rs
index f58c7d60094bcc5480b2db0896d3403a5591e9e4..94f2de8272dce104cd1ad1dbb471c3e98f6aaae3 100644
--- a/src/database/global_edus.rs
+++ b/src/database/global_edus.rs
@@ -1,5 +1,5 @@
 use crate::{Error, Result};
-use ruma::events::EventJson;
+use ruma::Raw;
 
 pub struct GlobalEdus {
     //pub globalallid_globalall: sled::Tree, // ToDevice, GlobalAllId = UserId + Count
@@ -47,8 +47,7 @@ pub fn update_presence(
     pub fn presence_since(
         &self,
         since: u64,
-    ) -> Result<impl Iterator<Item = Result<EventJson<ruma::events::presence::PresenceEvent>>>>
-    {
+    ) -> Result<impl Iterator<Item = Result<Raw<ruma::events::presence::PresenceEvent>>>> {
         let first_possible_edu = (since + 1).to_be_bytes().to_vec(); // +1 so we don't send the event at since
 
         Ok(self
diff --git a/src/database/globals.rs b/src/database/globals.rs
index d59e1c3498b21d9349cc43b586f0c8c1697b12f0..45786054ae35e46a168df676ebef4e965ab564f5 100644
--- a/src/database/globals.rs
+++ b/src/database/globals.rs
@@ -1,7 +1,7 @@
 use std::convert::TryInto;
 
 use crate::{utils, Error, Result};
-use ruma::identifiers::ServerName;
+use ruma::ServerName;
 pub const COUNTER: &str = "c";
 
 pub struct Globals {
diff --git a/src/database/key_backups.rs b/src/database/key_backups.rs
index eb31b8d0168bf2e4f66ce28359c11a1ed38d7d80..a50656471fb7aa39212fc8ca4ca604f6dc87feac 100644
--- a/src/database/key_backups.rs
+++ b/src/database/key_backups.rs
@@ -4,7 +4,7 @@
         error::ErrorKind,
         r0::backup::{BackupAlgorithm, KeyData, Sessions},
     },
-    identifiers::{RoomId, UserId},
+    {RoomId, UserId},
 };
 use std::{collections::BTreeMap, convert::TryFrom};
 
diff --git a/src/database/rooms.rs b/src/database/rooms.rs
index 7e6036ddc3c487cef797b77ef877cceb9d436ebc..5b9659efd6671fa6baa8b670768b2492fdf2d842 100644
--- a/src/database/rooms.rs
+++ b/src/database/rooms.rs
@@ -12,9 +12,9 @@
             power_levels::{self, PowerLevelsEventContent},
             redaction,
         },
-        EventJson, EventType,
+        EventType,
     },
-    identifiers::{EventId, RoomAliasId, RoomId, UserId},
+    EventId, Raw, RoomAliasId, RoomId, UserId,
 };
 use sled::IVec;
 use std::{
@@ -287,28 +287,24 @@ pub fn append_pdu(
                         })
                     },
                     |power_levels| {
-                        Ok(
-                            serde_json::from_value::<EventJson<PowerLevelsEventContent>>(
-                                power_levels.content.clone(),
-                            )
-                            .expect("EventJson::from_value always works.")
-                            .deserialize()
-                            .map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?,
+                        Ok(serde_json::from_value::<Raw<PowerLevelsEventContent>>(
+                            power_levels.content.clone(),
                         )
+                        .expect("Raw::from_value always works.")
+                        .deserialize()
+                        .map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?)
                     },
                 )?;
             let sender_membership = self
                 .room_state_get(&room_id, &EventType::RoomMember, &sender.to_string())?
                 .map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| {
-                    Ok(
-                        serde_json::from_value::<EventJson<member::MemberEventContent>>(
-                            pdu.content.clone(),
-                        )
-                        .expect("EventJson::from_value always works.")
-                        .deserialize()
-                        .map_err(|_| Error::bad_database("Invalid Member event in db."))?
-                        .membership,
+                    Ok(serde_json::from_value::<Raw<member::MemberEventContent>>(
+                        pdu.content.clone(),
                     )
+                    .expect("Raw::from_value always works.")
+                    .deserialize()
+                    .map_err(|_| Error::bad_database("Invalid Member event in db."))?
+                    .membership)
                 })?;
 
             let sender_power = power_levels.users.get(&sender).map_or_else(
@@ -339,24 +335,21 @@ pub fn append_pdu(
                             &target_user_id.to_string(),
                         )?
                         .map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| {
-                            Ok(
-                                serde_json::from_value::<EventJson<member::MemberEventContent>>(
-                                    pdu.content.clone(),
-                                )
-                                .expect("EventJson::from_value always works.")
-                                .deserialize()
-                                .map_err(|_| Error::bad_database("Invalid Member event in db."))?
-                                .membership,
+                            Ok(serde_json::from_value::<Raw<member::MemberEventContent>>(
+                                pdu.content.clone(),
                             )
+                            .expect("Raw::from_value always works.")
+                            .deserialize()
+                            .map_err(|_| Error::bad_database("Invalid Member event in db."))?
+                            .membership)
                         })?;
 
-                    let target_membership = serde_json::from_value::<
-                        EventJson<member::MemberEventContent>,
-                    >(content.clone())
-                    .expect("EventJson::from_value always works.")
-                    .deserialize()
-                    .map_err(|_| Error::bad_database("Invalid Member event in db."))?
-                    .membership;
+                    let target_membership =
+                        serde_json::from_value::<Raw<member::MemberEventContent>>(content.clone())
+                            .expect("Raw::from_value always works.")
+                            .deserialize()
+                            .map_err(|_| Error::bad_database("Invalid Member event in db."))?
+                            .membership;
 
                     let target_power = power_levels.users.get(&target_user_id).map_or_else(
                         || {
@@ -374,9 +367,9 @@ pub fn append_pdu(
                         self.room_state_get(&room_id, &EventType::RoomJoinRules, "")?
                             .map_or(Ok::<_, Error>(join_rules::JoinRule::Public), |pdu| {
                                 Ok(serde_json::from_value::<
-                                    EventJson<join_rules::JoinRulesEventContent>,
+                                    Raw<join_rules::JoinRulesEventContent>,
                                 >(pdu.content.clone())
-                                .expect("EventJson::from_value always works.")
+                                .expect("Raw::from_value always works.")
                                 .deserialize()
                                 .map_err(|_| {
                                     Error::bad_database("Database contains invalid JoinRules event")
@@ -581,18 +574,17 @@ pub fn append_pdu(
             EventType::RoomRedaction => {
                 if let Some(redact_id) = &redacts {
                     // TODO: Reason
-                    let _reason = serde_json::from_value::<
-                        EventJson<redaction::RedactionEventContent>,
-                    >(content)
-                    .expect("EventJson::from_value always works.")
-                    .deserialize()
-                    .map_err(|_| {
-                        Error::BadRequest(
-                            ErrorKind::InvalidParam,
-                            "Invalid redaction event content.",
-                        )
-                    })?
-                    .reason;
+                    let _reason =
+                        serde_json::from_value::<Raw<redaction::RedactionEventContent>>(content)
+                            .expect("Raw::from_value always works.")
+                            .deserialize()
+                            .map_err(|_| {
+                                Error::BadRequest(
+                                    ErrorKind::InvalidParam,
+                                    "Invalid redaction event content.",
+                                )
+                            })?
+                            .reason;
 
                     self.redact_pdu(&redact_id)?;
                 }
diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs
index b96f1b106cc401db51e6a85288cbf81d0411c23e..22d016664dae1c47cb6d66329c07faa8fde6bead 100644
--- a/src/database/rooms/edus.rs
+++ b/src/database/rooms/edus.rs
@@ -1,7 +1,7 @@
 use crate::{utils, Error, Result};
 use ruma::{
-    events::{AnyEvent as EduEvent, EventJson, SyncEphemeralRoomEvent},
-    identifiers::{RoomId, UserId},
+    events::{AnyEvent as EduEvent, SyncEphemeralRoomEvent},
+    Raw, RoomId, UserId,
 };
 use std::convert::TryFrom;
 
@@ -61,8 +61,7 @@ pub fn roomlatests_since(
         &self,
         room_id: &RoomId,
         since: u64,
-    ) -> Result<impl Iterator<Item = Result<EventJson<ruma::events::AnySyncEphemeralRoomEvent>>>>
-    {
+    ) -> Result<impl Iterator<Item = Result<Raw<ruma::events::AnySyncEphemeralRoomEvent>>>> {
         let mut prefix = room_id.to_string().as_bytes().to_vec();
         prefix.push(0xff);
 
diff --git a/src/database/uiaa.rs b/src/database/uiaa.rs
index d490499ae306289376c83f75b803dc1ab32fb667..4366eb2c644c80db16d04b6dbfbb32c8217bc5a2 100644
--- a/src/database/uiaa.rs
+++ b/src/database/uiaa.rs
@@ -4,7 +4,7 @@
         error::ErrorKind,
         r0::uiaa::{AuthData, UiaaInfo},
     },
-    identifiers::{DeviceId, UserId},
+    DeviceId, UserId,
 };
 
 pub struct Uiaa {
@@ -149,7 +149,7 @@ fn update_uiaa_session(
     ) -> Result<()> {
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         if let Some(uiaainfo) = uiaainfo {
             self.userdeviceid_uiaainfo.insert(
@@ -171,7 +171,7 @@ fn get_uiaa_session(
     ) -> Result<UiaaInfo> {
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         let uiaainfo = serde_json::from_slice::<UiaaInfo>(
             &self
diff --git a/src/database/users.rs b/src/database/users.rs
index 6e6258f5954fcea9362ece683bcf502695a911a6..5030f32e446e79fbd7bc05cbcdf981f155cf3aa1 100644
--- a/src/database/users.rs
+++ b/src/database/users.rs
@@ -8,8 +8,8 @@
             keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey},
         },
     },
-    events::{AnyToDeviceEvent, EventJson, EventType},
-    identifiers::{DeviceId, UserId},
+    events::{AnyToDeviceEvent, EventType},
+    DeviceId, Raw, UserId,
 };
 use std::{collections::BTreeMap, convert::TryFrom, mem, time::SystemTime};
 
@@ -177,7 +177,7 @@ pub fn create_device(
 
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         self.userdeviceid_metadata.insert(
             userdeviceid,
@@ -200,7 +200,7 @@ pub fn create_device(
     pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         // Remove tokens
         if let Some(old_token) = self.userdeviceid_token.remove(&userdeviceid)? {
@@ -246,7 +246,7 @@ pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator<Item = Result<Bo
     fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> {
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         // All devices have metadata
         assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some());
@@ -273,7 +273,7 @@ pub fn add_one_time_key(
     ) -> Result<()> {
         let mut key = user_id.to_string().as_bytes().to_vec();
         key.push(0xff);
-        key.extend_from_slice(device_id.as_str().as_bytes());
+        key.extend_from_slice(device_id.as_bytes());
 
         // All devices have metadata
         // Only existing devices should be able to call this.
@@ -305,7 +305,7 @@ pub fn take_one_time_key(
     ) -> Result<Option<(AlgorithmAndDeviceId, OneTimeKey)>> {
         let mut prefix = user_id.to_string().as_bytes().to_vec();
         prefix.push(0xff);
-        prefix.extend_from_slice(device_id.as_str().as_bytes());
+        prefix.extend_from_slice(device_id.as_bytes());
         prefix.push(0xff);
         prefix.push(b'"'); // Annoying quotation mark
         prefix.extend_from_slice(key_algorithm.to_string().as_bytes());
@@ -340,7 +340,7 @@ pub fn count_one_time_keys(
     ) -> Result<BTreeMap<KeyAlgorithm, UInt>> {
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         let mut counts = BTreeMap::new();
 
@@ -375,7 +375,7 @@ pub fn add_device_keys(
     ) -> Result<()> {
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         self.keyid_key.insert(
             &userdeviceid,
@@ -556,7 +556,7 @@ pub fn get_device_keys(
     ) -> Result<Option<DeviceKeys>> {
         let mut key = user_id.to_string().as_bytes().to_vec();
         key.push(0xff);
-        key.extend_from_slice(device_id.as_str().as_bytes());
+        key.extend_from_slice(device_id.as_bytes());
 
         self.keyid_key.get(key)?.map_or(Ok(None), |bytes| {
             Ok(Some(serde_json::from_slice(&bytes).map_err(|_| {
@@ -643,7 +643,7 @@ pub fn add_to_device_event(
     ) -> Result<()> {
         let mut key = target_user_id.to_string().as_bytes().to_vec();
         key.push(0xff);
-        key.extend_from_slice(target_device_id.as_str().as_bytes());
+        key.extend_from_slice(target_device_id.as_bytes());
         key.push(0xff);
         key.extend_from_slice(&globals.next_count()?.to_be_bytes());
 
@@ -664,12 +664,12 @@ pub fn get_to_device_events(
         &self,
         user_id: &UserId,
         device_id: &DeviceId,
-    ) -> Result<Vec<EventJson<AnyToDeviceEvent>>> {
+    ) -> Result<Vec<Raw<AnyToDeviceEvent>>> {
         let mut events = Vec::new();
 
         let mut prefix = user_id.to_string().as_bytes().to_vec();
         prefix.push(0xff);
-        prefix.extend_from_slice(device_id.as_str().as_bytes());
+        prefix.extend_from_slice(device_id.as_bytes());
         prefix.push(0xff);
 
         for value in self.todeviceid_events.scan_prefix(&prefix).values() {
@@ -690,7 +690,7 @@ pub fn remove_to_device_events(
     ) -> Result<()> {
         let mut prefix = user_id.to_string().as_bytes().to_vec();
         prefix.push(0xff);
-        prefix.extend_from_slice(device_id.as_ref().as_bytes());
+        prefix.extend_from_slice(device_id.as_bytes());
         prefix.push(0xff);
 
         let mut last = prefix.clone();
@@ -725,7 +725,7 @@ pub fn update_device_metadata(
     ) -> Result<()> {
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         // Only existing devices should be able to call this.
         assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some());
@@ -748,7 +748,7 @@ pub fn get_device_metadata(
     ) -> Result<Option<Device>> {
         let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
         userdeviceid.push(0xff);
-        userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
+        userdeviceid.extend_from_slice(device_id.as_bytes());
 
         self.userdeviceid_metadata
             .get(&userdeviceid)?
diff --git a/src/pdu.rs b/src/pdu.rs
index 0db77a1a590d993361fc1b9d37a7d4410116b3be..0cfdb6391f426bd43c951c684c7cddd117358e22 100644
--- a/src/pdu.rs
+++ b/src/pdu.rs
@@ -3,10 +3,9 @@
 use ruma::{
     events::{
         pdu::EventHash, room::member::MemberEventContent, AnyRoomEvent, AnyStateEvent,
-        AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventJson, EventType,
-        StateEvent,
+        AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
     },
-    identifiers::{EventId, RoomId, ServerName, UserId},
+    EventId, Raw, RoomId, ServerName, UserId,
 };
 use serde::{Deserialize, Serialize};
 use serde_json::json;
@@ -79,40 +78,40 @@ pub fn redact(&mut self) -> Result<()> {
         Ok(())
     }
 
-    pub fn to_sync_room_event(&self) -> EventJson<AnySyncRoomEvent> {
+    pub fn to_sync_room_event(&self) -> Raw<AnySyncRoomEvent> {
         let json = serde_json::to_string(&self).expect("PDUs are always valid");
         serde_json::from_str::<AnySyncRoomEvent>(&json)
-            .map(EventJson::from)
+            .map(Raw::from)
             .expect("AnySyncRoomEvent can always be built from a full PDU event")
     }
-    pub fn to_room_event(&self) -> EventJson<AnyRoomEvent> {
+    pub fn to_room_event(&self) -> Raw<AnyRoomEvent> {
         let json = serde_json::to_string(&self).expect("PDUs are always valid");
         serde_json::from_str::<AnyRoomEvent>(&json)
-            .map(EventJson::from)
+            .map(Raw::from)
             .expect("AnyRoomEvent can always be built from a full PDU event")
     }
-    pub fn to_state_event(&self) -> EventJson<AnyStateEvent> {
+    pub fn to_state_event(&self) -> Raw<AnyStateEvent> {
         let json = serde_json::to_string(&self).expect("PDUs are always valid");
         serde_json::from_str::<AnyStateEvent>(&json)
-            .map(EventJson::from)
+            .map(Raw::from)
             .expect("AnyStateEvent can always be built from a full PDU event")
     }
-    pub fn to_sync_state_event(&self) -> EventJson<AnySyncStateEvent> {
+    pub fn to_sync_state_event(&self) -> Raw<AnySyncStateEvent> {
         let json = serde_json::to_string(&self).expect("PDUs are always valid");
         serde_json::from_str::<AnySyncStateEvent>(&json)
-            .map(EventJson::from)
+            .map(Raw::from)
             .expect("AnySyncStateEvent can always be built from a full PDU event")
     }
-    pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEvent> {
+    pub fn to_stripped_state_event(&self) -> Raw<AnyStrippedStateEvent> {
         let json = serde_json::to_string(&self).expect("PDUs are always valid");
         serde_json::from_str::<AnyStrippedStateEvent>(&json)
-            .map(EventJson::from)
+            .map(Raw::from)
             .expect("AnyStrippedStateEvent can always be built from a full PDU event")
     }
-    pub fn to_member_event(&self) -> EventJson<StateEvent<MemberEventContent>> {
+    pub fn to_member_event(&self) -> Raw<StateEvent<MemberEventContent>> {
         let json = serde_json::to_string(&self).expect("PDUs are always valid");
         serde_json::from_str::<StateEvent<MemberEventContent>>(&json)
-            .map(EventJson::from)
+            .map(Raw::from)
             .expect("StateEvent<MemberEventContent> can always be built from a full PDU event")
     }
 }
diff --git a/src/push_rules.rs b/src/push_rules.rs
index 5bc0d74453e48dbb73ee97f151b370fd9e03b54e..a1f32f4d06266be1f1a18a46e1b5855793f8a4ec 100644
--- a/src/push_rules.rs
+++ b/src/push_rules.rs
@@ -1,6 +1,6 @@
 use js_int::uint;
 use ruma::{
-    identifiers::UserId,
+    UserId,
     push::{
         Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule,
         PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak,
diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs
index cd2d21e3683f21a2d91b34a8fa3c42b7f7005ace..15e50ba3250047d44c2f662d1b44ce6a93ea09af 100644
--- a/src/ruma_wrapper.rs
+++ b/src/ruma_wrapper.rs
@@ -7,10 +7,7 @@
     Outcome::*,
     Request, State,
 };
-use ruma::{
-    api::Endpoint,
-    identifiers::{DeviceId, UserId},
-};
+use ruma::{api::Endpoint, DeviceId, UserId};
 use std::{convert::TryInto, io::Cursor, ops::Deref};
 use tokio::io::AsyncReadExt;