remove extra newline and spaces on empty lines