moved code to Model, refined layout