replaced "document.onclick" with "addEventListener" + misc improvements