fix error on most recent vote sorting and refactor code