Added error detection