Fixed a typo so insertion works into server. Added minor error checking