added comments
added threading