The purposes are described in comments of the functions