Made many changes to script, removed most of the errors, improved the array structure of data