implemented sessions and changed err to err.message for error handling