reordered code for posting in the article