fix bugs in models and add unit test