Code changes in line with the issues described in ticket #666. The problems fixed in this commit prevented the model from running FG4 in debug mode