AI improved, restructured code