Added logout method and improved error handling
Added integration tests