some useful comments and refactor to the code