There seems to be some duplication between the above 2 and below 2 lines.  Make it a function?