Use more modularised code taken from nypl repo gem