Fixes #1, #2, #3 - Fixing security bugs

@simonwex

These are our proposed fixes for issues 1-3.