Restructured code, improved outputs