refactor from function -> object