Fix the superclass
Remove useless old version
Improve security by storing hashed sids in the database.

Also remove some unnecessary database queries.