refactored and objectified the js