Added some risk management.

Still needs to be cleaned and improved.