Key model and some bug fix