Adding some error handleing and testing.