Fixed indexing error in err while plotting