cleanup and add debugging