Refactor of hardware.py