Fix issues with bad querryset for issue #1477