Add logic to handle abnormal situations. Add comments.