refactored citation code to be cleaner