refactored some code into a shared js