Ported over more code from messaging app