Refactor JS app