exported some javascript calls from html code to listeners
reworked some logics