Added writeCandidates() function