prevent undefined index
updated version
corrected var name and removed old code
improved formatting
prevent illegal string offset warning and formatting
updated version