merge kai's code