- modified some logic, comments are added to clarify every change
Authored by: agalal 2011-09-17
Parent: [r328]
Child: [r330]