optimze code , add test code