Refactored serial init code