added header and some code cosmetics