Fixed bug when emptying array