Add APPNAME defines, some other minor improvements