more modification to model and some other minor refactoring