Reorganize code + make serial device configurable