Used dynamic arrays to clean the code up further.