adapted code regarding to the disussion at github