move logic to js