Added some more function result checking, added template params