Code revised and pthread code modified.