Allow core.cleanup to take arbitrary arguments
Clean up correctly when exiting in log input loop