adding exception handling and template convience functions