LUN-66 fixed orphan templates + refactoring of duplicted code