Port over base connectivity code from other app. Refactor.