Html Write Function and Refactor