use 'unless' and 'error' to simplify main