refactered model and fixed tests