Trying to resolve pthread bug