Code opens and closes