Cleanup of dead code and write statements.