Refactor so js can be used for other types also