cleaned up the php, added a couple more comments