fixed bug and changed how array is emptied