Reformatting and refactoring the code