Further cleaned up code and implemnted displayData function