Better cleaning of instance when starting and ending