adding batch method to Yann's code
fix syntax error