protect against undefined
Handle empty datasets without crashing. Closes #400