Fix javascript issues and consolidate in application.js file.