refactor and add templates