formatting and removing redundant lines