Added optional and class method support, error handling