Make some further changes to avoid possible latency

- Use sum of squares equation to calculate instead of simple for loop

- Output final result directly from Master instead of sending to Listener