refactoring code on view