Added error codes. Structural changes etc...