Removed unnecessary import of sys
Changed has_key to "in"
Removed unneeded events