Added more comments into code. Edit php sections to make it easier to understand.