refactored common javascript