Fix issue 310

The first commit is not strictly needed, but it is a better practice. The real fix is inside the second commit.