simplified some functions; removed sqrt(not a stats function)