Refactor, implemented templates