JS: finish function