adding error checking and cleaning format