Cleanup and debugging code