Rewrote populate function to be general purpose