robustified code to work when not called from the web application