working version of stochastical laph code