refactored the code to work in a multiple node environment