Added some error handeling