Created function to remove repeated code.