Refactored serial connection creation into a factory