Move code to separate function to make it re-usable.