refactor code to separate html generation

@sethladd