Clean up code and use objects instead of array