fixed subscript in sum; added new functions; fixed allocation of theta