Fixed reuse of the Y variable as a bug, made the final clean up statment be more robust.