Fix errors, some cleanup. I hadn't touched the code in ages.