added pthread_join and other minor changes