Refactor to remove magic numbers in JS