Fixed missing cleanup

Also moved some things around