Improved a few things with arrays, added better error checking