ported. comments needed
ported