Final version with cleanup