Added checking for NULL arrays