Refactor fromInteger method to use factory