Fixed sume bugs and added debug mode.