Added some exceptions handling and testing