Fixing bugs discovered by James.