Added error function and replaced assert calls.