refatoring vote function's code