refactor js into pieces of js