begin to probability and flatten code