Move cleanup code to update versions function