Restructured code, removed global passy