added threading functionality