JSON output and finally understood selling logic