fixed bug in whole, and clarified code further