Added some checks for empty data values to prevent errors