code cleaning; added a few features mainly to improve output generation