Code cleaup, document errors