Compile fixes, cleanups, better references