more modular
first version of code with prior information