Several changes & optimisations

Please check before merges (not tested), it is updated from another module (node-red function)