refactored php and js