Added debug mode; minor clean up