refactoring target controller
improved error handling for targets and templates