fixed warning and logic problem