A.F....... [ZBXNEXT-1782] refactored the code to avoid similar problems in the future