fix equal sign in valid(), avoid dividing by zero in main