Fixed PHP coding style, added edge cases to jquery