Code divided into master/slave functions and tested.
TODO: divide work if its more than no. of processors