made some changes to clear function