manually merging qilin's code