reduce js code duplication