Function structured python script and improvements in the output