For some time I have blindly run latex commands until I got a PDF file with the correct references. After reading some source and SF posts, I believe I have figured out the correct way to do it.
latexmk -c main.tex; pdflatex main.tex; bibtex main; pdflatex main.tex;
latexmk -c main.tex
cleans the directory.pdflatex main.tex
generates auxillary files and figures out what bib entries it needs.bibtex main
compiles the bibliography.pdflatex main.tex
generates the final PDF.