added threading and error messages