reorganized to reduce redundant code between firmwares