cleanup and setcode