Simplified by adding a dictionary

1. I replaced `data[][]` with a dictionary which made it easier to read the code.
2. I also removed several functions that didn't really need to exist, as the code only appeared once.
3. I also removed some of the commenting as I felt it didn't add any value.