fixed a bug and formatted table
added header and changed some php placement