First merge of Kim's code