Complete initial implementation

It's a complete mess, but it works!