Tweaked some functions to handle missing data