Refactored internal connector into separate factory class. Also performed some other code cleanup