Improved session system and SQL connection