Fix some bugs.

This doesn't work anymore, so I made some changes to make it work, at least.