This is still pretty WIP, but it at least gets the functionality back to where it was before.
This isn't a good implementation by any means. It's just to get things started.