added coments to JavaScript and refactored actions in controler