Fixed this before in a test plugin but never fixed it at the root of the problem.