Refactor JS, separate responsibilities, remove harcoded constants