improve style and add more comments