WIP refactor and add connectivity test (buggy)