arrays should not be deleted before being created. Moved the del functions at the right place