Make bgapp a global. Add constants for reuse