refactored. cleaned up JS