Bugfix: adding some important checks to the insert operation