Refactor the code. Using template now.