basic algorithm working; just slow