refactored functions-js