Code Refactor and refine