Make reusable function for registering S3 methods