Added checks to avoid NullPointerException when converting arrays to lists