Code re-structuring and added insert() interface