Reduce the duplicate code to create candidate button