initialize variables and added checks for empty data