Security

I've made a few changes to get rid of security flaws. Be wary when merging.