Refactor code and get data into arrays