split writing functions block into 3 parts