refactor
add protection against leaking private data
add missing cases