refactoring code for use in an mvc framework