From: hasan on
codes are between lines 288 to 305