now uses case and can accept pipe input