updated to handle sessions