Added threading functionality