Improve testability

mv JS to JS files and out of PHP files