refactored js-code to better apply a MVC-pattern