adds some error handling to make things work better