modbus function rewritten