Added some security measures

whitelisted acceptible chars.

Also found a few small bugs.