refined the code.