refactor and convert clean command to js, fix test