Code Refactor and reformatting