Auto-formatting and removing some redundant lines