Refactor objects function