Re-coded procedure to a fucncition.