Initial implementation. Still lots of bugs to deal with, but it works at a basic level.