Improve populate function