Backend implementation

Lots and lots and lots of stuff.