Refactored pseudo-terminal code into pts.c