Added more error handeling