this function is too long now. please split it up in small logical units (>3 I guess)