Added bucket logic to the insert.