Added error handaling