refined the code