Bug fixes

Various fixes to trace back errors