Finally implemented check function for insertion