refactored so can run in debug