Succesfully pass variable to thread function