update clear function.
Add penalty calculating.