Separated common codes into short functions.