fixing Q, step1: from Joseph gist to python (observed variable terms are commented out for now)