Stof patch 

This PR replaces https://github.com/avalanche123/Imagine/pull/384