Improved JavaScript code

Moved code to separate file (/js/ace.js) and improved it's organization.