remove trail spaces and compress empty lines