added code for collapse the periods