fix sqrt  bug reported by Eric Garcia from Less Neglect and some minor issues with sparse input