Fix flags variable being set

If an exception is raised, this is thrown:

UnboundLocalError: local variable 'flags' referenced before assignment

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
Merge pull request #17 from bfirsh/fix-flags-variable-not-being-set

Fix flags variable being set