Fixing neverending array bug