first pass at python version of cap alg
finished porting to python; debugging