Reformatting and cleaning up the code