works ok, but get rid of mutables
output