Fixed a bug with the sed function and formated the code