Refined the code