Fixed most of the issues raised in prior code review. Need to fix caching of theano functions