encapsulate js functionality better