condensed code and added header comment