Moving citation tool code in API module into its own function

This should slightly improve the readability and modularity of the
code.

Change-Id: Ie4dcbeca550129c2fcea69f011d0297f334ea235