Stored queries mutable state side effects issue

This is to address issue #205

Not ready for merge yet!