Move appname determination to method