Multiple updates: added special character escaping, added support for commas in values. removed possible index out of bounds errors, cleaned up code.