Simplify gamble function, add comments, fix bugs