improved model and fixed bugs