end case correction

made some changes after considering end cases