edited and cleaned up bg_sub