added more conditionals to filter out undefineds