Added safety check in parents and closest (closes #200)