Fixed some errors causing ClassCastExceptions

Casting Object[] to an array of a different type causes a ClassCastException during runtime (at least on my computer); using the version of toArray that takes an array as an argument fixes this problem.