Move the PBAP code away from the main method and into functions