refactored php/html code in view