added parameter to control experiment length, and bug fix