fix bug with error handeling