better error messages
polish the logic