Added error logic