fixed off-by-one errors and separated checkCandidates into two methods