Fixed race condition in test and added more comments